This peice of code will show you some memory management in classes.
When we give application to client, we dont know how will he use that whether he will call dispose or not?
It may be missing at client side so our application should be smart enough to free used resources, here is code
which will give Idea to implement finalizer and dispose in same class to take care of resource cleaning.
class ResourceManagement : IDisposable
private bool IsDisposed = false;
public void Free()
throw new System.ObjectDisposedException("Object Name");
//Call Dispose to free resources explicitly
public void Dispose()
//Pass true in dispose method to clean managed resources too and say GC to skip finalize
in next line.
//If dispose is called already then say GC to skip finalize on this instance.
//Pass false as param because no need to free managed resources when you call finalize it
will be done
//by GC itself as its work of finalize to manage managed resources.
//Implement dispose to free resources
protected virtual void Dispose(bool disposedStatus)
IsDisposed = true;
// Released unmanaged Resources
// Released managed Resources