0

Hi guys,

Is it necessary to use destructor in c# to terminate any created objects??

Thanks in advance

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by sknake
0

Destructor is a very special method of class and it is used to implement object specific cleanup code. Unreferenced objects are released by the Garbage collector.

Edited by __avd: n/a

0

MSDN:
The programmer has no control over when the destructor is called because this is determined by the garbage collector. The garbage collector checks for objects that are no longer being used by the application. If it considers an object eligible for destruction, it calls the destructor (if any) and reclaims the memory used to store the object. Destructors are also called when the program exits.

Take a look at these:
Destructors
Dispose

0

The links DdoubleD posted should explain it, and more than likely if you're asking that question then you don't need a finalizer. The finalizer/destructor gives you one more chance to free up unmanaged resources so they're not leaked.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.