As of my knowledge i know like GC performs collection operation in order to remove unmanaged resources to release memory which is called implicit clean up. And by using ‘USING’ keyword we can do it explicit cleaning but my doubt is how GC releases managed resources.
Share
You don’t have to do anything special in order for GC to clean up your managed resources. GC will clean it up sometime after there are no references left to your managed resource.
If your managed resource owns unmanaged resources, you can implement the IDisposable interface and call the
Disposemethod, in which you’d explicitly clean up your unmanaged resources.usingstatement makes it very easy to use this interface, as it automatically calls Dispose when the code exists theusingblock, even in case of exceptions.You might take a look at the MSDN documentation on Garbage Collection.
EDIT: based on comments above.
You could override
Object.Finalizeby defining a finalizer (e.g. ~MyClass()) but there is no telling when it will be called by GC. IDisposable is generally preferred. More info on Finalizer vs Dispose here.