Hi guys,
Is it necessary to use destructor in c# to terminate any created objects??
Thanks in advance
Hi guys,
Is it necessary to use destructor in c# to terminate any created objects??
Thanks in advance
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.
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
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.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.