O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Destructors (Poorly Named Finalizers)

Besides constructors, C# has the notion of destructors. Before going any further, let’s start with the mandatory warning. In the world of garbage collection, destructors only share their name with the concept known from C++. That is, they are totally different in behavior, despite their common syntax. To put this straight, consider the following piece of C++ code. Readers unfamiliar with C++ can skip the following example:

#include <stdio.h>class Destruct{public:    Destruct() {        printf("Constructing\n");    }    ~Destruct() {        printf("Destructing\n");    }};void Stack() {    printf("Stack - begin\n");    Destruct d;    printf("Stack - end\n");}void Heap() {    printf("Heap - begin\n");    Destruct ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required