Last post Jun 25, 2014 09:18 AM by rds80
Jun 24, 2014 05:39 PM|rds80|LINK
The class Microsoft.SqlServer.Dts.Runtime.Application doesn't implement the IDisposable interface nor does it have a Close method. What is the best practice to remove this object from the GC?
On a high level, I was thinking the best practice would be to:
1) Create a wrapper class of the Application class
2) Implement the IDisposable interface
3) In the Dispose method set the instance of the class to null.
Please let me know if that's correct.
Jun 24, 2014 06:02 PM|BrockAllen|LINK
Sounds like you're unclear on the difference between memory and non-memory resources. IDisposable is ultimately for non-memory/unmanaged resources. It has nothing to do with memory or the GC.
The rule is if an object implements IDisposable then you need to call it because ot holds a non-memory resource that's not managed by the .NET runtime and needs to be cleaned up. Otherwise if it doesn't implement IDisposable then it doesn't have any resource
other than memory (meaning the object itself) and in this case don't worry about it -- the GC will take care of it.
Jun 25, 2014 09:18 AM|rds80|LINK
Thanks for the explaination. You're right I didn't know the difference.
So a memory resource (such like the Application class as mentioned above) when instantiated resides on the heap. Therefore, when a method (for example) is done using the instance of the class the GC will take care of destroying that instance on the heap.
However, for a non-memory/unmanaged resource that implements the IDisposable interface, the developer is required to dispose the object from the heap. Is this correct?
If I was to create a new class, what resources do I need to use that would require me to implement IDisposable?