Hong Zhang wrote:
> Most of finalization is used to deal with external resource, such as open
> file, socket, window. You don't really want to depend on finalization,
> since it is very likely run out of default file descriptor limit before
> the finalization kicks in. The rule of thumb is to let finalization to
> cleanup resource when an unexpected exception happens. It is more like
> a safe-net or parachute. It is most likely to help you in emergency, but
> there is no guarantee it will work.
>
There's a really interesting paper by one of the .NET development team
explaining why finalization and GC just don't go together:
  http://www.mvps.org/vbnet/dev/vb7/vbdotnet_ms_resmanagement.htm

The answer used in .NET is to have a dispose() method (which is not a
special name--just an informal standard) that the class user calls manually
to clean up resources. It's not an ideal solution but there doesn't seem to
be many other practical options.


Reply via email to