Re: Finalizer vs. Dispose

From: Chris Lyon [MSFT] (clyon_at_online.microsoft.com)
Date: 03/18/05


Date: Fri, 18 Mar 2005 01:45:02 GMT

Brock makes a good point. You can read more on Dispose guidelines here:
http://blogs.msdn.com/clyon/archive/2004/09/21/232445.aspx
http://blogs.msdn.com/clyon/archive/2004/09/23/233464.aspx

Hope that helps
-Chris

--------------------
|
| > Mostly all .NET classes which implements IDisposable, also implements
| > an finalizer.
|
| I disagree. The Finalizer is really there for non-managed resources that
| the GC has no idea how to properly cleanp. Think Win32 handles that your
| code went out thru interop to acquire. If you don't have those sorts of
resources,
| then don't implement a Finalizer as it slows your app down and the memory
| for your objects hang around longer than they need to. I'd say the
converse
| is more accurate: "All classes that have a Finalizer should also
implement
| IDisposable".
|
| IDisposable, as already mentioned, is just a pattern that alerts the
client
| of your code that Dispose needs to be called as soon as you're done with
| this object. This allows more aggresive cleanup of resources (both
managed
| and unmanaged). If all you hold are managed resources, then IDisposable
is
| sufficient, yet important.
|
| -Brock
| DevelopMentor
| http://staff.develop.com/ballen
|

|
|



Relevant Pages

  • Re: Finalizer vs. Dispose
    ... > Mostly all .NET classes which implements IDisposable, ... > an finalizer. ... If you don't have those sorts of resources, ... If all you hold are managed resources, ...
    (microsoft.public.dotnet.framework.clr)
  • Re: " //Clean Up managed resources " f&*ck
    ... The finalizer is called by the GC. ... time (such as releasing internal unmanaged resources). ... Since Dispose ... it is about 'managed resource'. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Dipose vs Destructor
    ... resources and native resources in a managed C++ class? ... C++/CLI implements the destructor and finalizer semantics in any ref class T ... These cleanup mechanisms are hidden from the C++/CLI ...
    (microsoft.public.dotnet.languages.vc)
  • Re: GC and dispose
    ... resources as well as unmanaged. ... We tend to use the Finalizer ... The Dispose method should be used to free resources. ... protected virtual void Dispose ...
    (microsoft.public.dotnet.framework)
  • Re: Finalizer vs. Dispose
    ... I think when we have the IDisposable interface ... > finalizer is better than implementing the IDisposable interface? ... Implement IDisposable if you need to free unmanaged resources. ... Mostly all .NET classes which implements IDisposable, ...
    (microsoft.public.dotnet.framework.clr)