I respectfully disagree that 3 is the most important option. The reason for
the finalizer is to ensure that unmanaged resources get cleaned up even if
the developer using the object forgets or is too lazy to call Dispose and/or
an exception in his or her code causes the calling of an object's Dispose
method to not occur. The finalizer will clean up the unmanaged resources
when the object itself is destroyed.

The fact is that very few classes need any dispose pattern at all. Those
classes that do need a dispose code pattern need to use option 2.

--Paul Mehner


The thing with relying on the finalizer to release an unmanaged resource is that by the time the finalizer runs it might be already too late. If the resource is scarce the system might have failed already before the finalizer runs. So rather than have the finalizer silently release the unmanaged resource, I'd fail an assertion or log it as an error somewhere (and release the resource if in release mode). This way, hopefully, the programmer is alerted to the leak problem and knows to fix it.

Regards,
Sami

===================================
This list is hosted by DevelopMentor�  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to