more on dotnet, gc, and memory management
this first example creates an object Test1 which has a destructor, an object Test2 which is derived from Test1 and has it's own destructor, and finally, a structure which is not allowed to have a destructor.
well, here is the code:
With Line Numbers and
Without Line Numbers
which produces the following output:
BEGIN:
Create a new Test1
Test1 (blah) Constructor
Create a new Test2
Test1 (foo) Constructor
Test2 (foo) Constructor
Create a new Test3
Start First Collection Point
Test2 Finalize [foo]
Test1 Finalize [foo]
Test1 Finalize [blah]
End First Collection Point
END
things to notice:
- the constructor for Test1 is called prior to the one for Test2 when you create a Test2 object
- the destructor for Test1 is called after the one for Test2 when you finalize a Test2 object
the second example
|