hi, iam little confuse about garbage collection,,pls clarify my confusions,,,,,
i used dispose method like
Timer tobg=new Timer();
tobj.dispose();
iam not used idisposible interface,, what is the difference?
Another confusions is exmaples of managed and unmanaged resources,,,
Loading
VulpesPosted Nov 12, 2013, 5:13 PM
Calling the Dispose() method releases the unmanaged resources used by the Timer (namely the use of the System clock which is an operating system resource) and therefore leaves the Timer in an unstable state. However, the Timer object won't become eligible for garbage collection until there are no longer any references to it so (unless it's about to go out of scope anyway) you should set tobj to null after calling Dispose().
The Dispose() method only needs to worry about unmanaged resources because managed resources used by the object will be cleaned up automatically when garbage collection takes place in any case. Unmanaged resources won't be dealt with by the garbage collector and failing to take appropriate action could therefore result in a resource leak which won't be plugged until the process itself ends. However, well written classes normally include a provision in the destructor to clean up unmanaged resources if the Dispose() method hasn't been called already.