As a programmer, I wonder since GC (Although we don't know when it starts to work, but according to MSDN, it will release resources that aren't referred by any active threads...ect). Since these resouces are USELESS, why don't we put codes of managed resource releasing in the destructor function? Something like this following:
public class A
{
private bool _isDisposed = false;
public void Dispose()
{
if(!_isDisposed){
// Release unmanaged and managed things
……
// Set to false to mark this class has been totally freed...
_isDisposed = true;
}
}
~A()
{
Dispose();
}
}
Any special reasons why we ONLY PUT unmanaged things in the destructor function but NOT ALL?
Take this as an example:
A a = new A();
a = null;
Something but very simple to tell you that the instance "a" WON'T BE REFERRED by any active threads (or else it cannot be collected by GC). So why don't let the destructor function release all the resources in it???