Ran across some code on the net that incorporates "dispose" 2
different ways..
I understand a calling routine could use the .Dispose on your class,
but I was under the impression "Dispose()" was the same thing as the
deconstructor in the following example (~YourClassNameHere()).
What would cause the deconstructor to fire off over the "Dispose()"
routine?
Would the deconstructor get called first, and then the Dispose() last?
If so, why not just have one simple "Dispose()" routine?
Snapshot of the Code:
internal class YourClassNameHere : MarshalByRefObject, IDisposable
~YourClassNameHere()
{
dispose( false );
}
public void Dispose()
{
dispose( true );
}
private void dispose( bool disposing )
{
if( disposing )
{
a = null;
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
System.GC.Collect( 0 );
}
}