The destructor are like constructor, called automatically before obhect get's destroy, It is important to note that the destructors are also called Finalizers in C# destcuctor is called as Finalize method. Called after TRY...CATCH block.
The IDisposable interface contains a method Dispose(), we can freeing up of unmanaged resources using Dispose() method. we can impelemnt IDisposable intgerface to any class here is code
public class Channel : IDisposable
hope it helpsThanks Koolprasd2003 Editor, DotNetSpider MVM Microsoft MVP 2014 [ASP.NET/IIS]
The garbage collector reclaims object memory when there are no valid references left for the object by calling Finalize method.
But we as a programmer might want to release some objects from memory like database connections explicitly, if no more processing is left with those objects. So instead of depending upon garbage collector to reclaim that memory (which is generally expensive in terms of size) , we explicitly release those resources by calling Dispose method.Hope it'll help you. Regards Ajatshatru
Hi, Unmanaged resources are released by using Dispose method by developers.Once we are finished with expensive resources such as windows handles, database connection, file system, we can call Dispose method instead of depending up on garbage collector. Finalize is called from the garbage collector if dispose is not called. The garbage collector calls this method only if there are no valid refernces to any particular object.
Finalize(): Finalization is the process by which the GC allows objects to clean up any unmanaged resources that they're holding, before the actually destroying the instance.
Dispose(): Dispose method called explicitly on any object that implements it to free any unmanaged resources for which the object may be holding references. The Dispose method generally doesn't free managed memory.