Click here to Skip to main content
14,872,052 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Do we call Dispose method even for managed objects? If it is for only for Unmanaged objects, why do we call GC.SupressFinalize() method at the end of Dispose?

Thanks,
D Apparao
Posted

You need to dispose all objects that implements IDisposable. That's why they implement IDisposable interface.

GC.SupressFinalize requests that the system not call the finalizer for the specified object. (GC=Garbage collection) SuppresFinalize should only be called by a class that has a finalizer. It's informing the GC that this object was cleaned up fully.
   
Comments
Mr Apps 25-Apr-13 4:07am
   
When do I need to implement IDisposagle interface? I did not get your point "SuppresFinalize should only be called by a class that has a finalizer". Can you please make this more clear?
StianSandberg 25-Apr-13 4:47am
   
You need to implement IDisposable in your classes if you have to clean up anything after it has done it's job. Then you can run som code after object is used.
A class can also have a "destructor" (MSDN Destructors (C# Programming Guide)). Using GC.SupressFinalize you tell the object not to "execute" this destructor.
it's not for only unmanaged object, it's for both

SupressFinalize just disabled so called 'destructor' because we already manualy destroyed the object
   

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