Cleanup and random errors

  • Thread starter Thread starter Claire
  • Start date Start date
C

Claire

I've noticed a couple of problems recently concerning 3rd party controls and
garbage collection. "Sometime" when the garbage collector decides to deal
with an object, if there's a problem in its destructor, you'll get errors
that are very hard to debug or find out where they're coming from. It's a
concern that really makes me dislike .net. I prefer to handle
construction/destructors manually.
Is there no other way than implementing Dispose so you can forcibly destroy
an object when you've finished with it ?

Claire
 
Hi Claire,

You may want to take a look at Finalize() which is the method called when the object is about to be destroyed.

It is generally best not to use it. It has the side effect of slowing down the garbage collector, and potentially dangerous as you can reattach references and mess up the garbage collector etc. And you can't be certain that it will run at all.

Dispose does not destroy an object, but it will cause the object to release resources and thereby speed up the GC and generally do a cleaner 'exit'. The 3rd party control should implement Dispose and you should call it when you are finished with it.
 
Back
Top