Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In order to Dispose an object , first the class referenced to that object must be inherited from Idisposable,.....

but once a class is inherited from Idisposable but If dispose() method is not explicitly called on object means , will that object gets disposed????

what is the use of IDisposable if class inherited from IDisposable but Dispose() is not used???
Posted
Updated 18-Oct-11 23:11pm
v2

Yes, it will - eventually.

If you do not use Dispose on an object that implements IDisposable, then it will be called automatically by the framework when the Garbage Collector realizes it is no longer needed and starts to delete it.

NOTE: This is not the same time as the object drops out of scope! The Garbage Collector may not get round to your object for hours, days or even weeks. If you create any object that implements IDisposable, then you are responsible for disposing of the object correctly, or problems can be expected. A simple example is to open a file for reading and not dispose of the stream object. If your application later tries to write to the file, it will get "File in use by another application" because the stream still exists (although it has no references) and is holding the file until the GC removes it. Frustrating, and annoying!
 
Share this answer
 
Comments
m19anand 19-Oct-11 5:04am    
thanx for ur answer,....

but my case is, im unable to dispose the object of class which implements Idisposable , because the class is a Eileo class and data is cuming from eileo server so im unable to dispose the object of that class..

please give some suggetion
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900