Sami said: > 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
Hopefully I did not give the impression that I was advocating that developers depend upon the finalizer for clean up of unmanaged resources. That is *not at all* what I intended.
If an unhandled exception occurs before an object has an opportunity to clean up its unmanaged resources the finalizer is there as a safety net to ensure that the resources do eventually get cleaned up (albeit late). It is better to be late with respect to cleaning up resources than to never clean them up. The finalizer also catches the circumstance where a developer doesn't call Dispose when they were supposed to (albeit late as well).
--Paul Mehner
I understood that you are not advocating releasing resources in the finalizer. My point is just that if a finalizer detects an unreleased unmanaged resource it should probably flag it as an error rather than dispose of the resource silently.
A good example is the SqlConnection class in an ASP.NET application. If a programmer forgets to call Dispose or Close on every instance then in my experience you are almost guaranteed to run into the "no more free connections in the pool" condition, at which point the application becomes effectively unusable for some time. It would be better IMO if SqlConnection had a finalizer that notified the developer that there is a leak.
Regards, Sami
=================================== This list is hosted by DevelopMentor� http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
