Hi, I might be thinking wrong, please correct if I am wrong.
To cleanup memory (Specially for unmanaged resources), we implement IDisposable interface and impelement Dispose method in which we write our custom logic to free memory.
So, my question is that as we are writing our own logic to free memory, can't we do same in any public method of our cass ?
Means actually we don't need IDisposable and Dispose method for this ? May be we use these for this kind of reasons-
1. Just for standardization that they are same across all applications
2. Once we say class implements IDisposable interface, we make sure that we don't miss dispose method implementation as we'll get error
if we forgot to give implementation for dispose method.
OR there is some other reason for using IDisposable. Please share your thoughts.
For example-
public class MyClass{
public void ReleaseMemory(){
ReleaseMemory(true);
GC.SuppressFinalize();
}
public void ReleaseMemory(bool releasing){
//all memory cleanup logic
}
}
Does this solve the purpose without implementing IDisposable interface ??