Re: Finalizer vs. Dispose
From: Jochen Kalmbach (nospam-Jochen.Kalmbach_at_holzma.de)
Date: 03/17/05
- Next message: Brock Allen: "Re: XCopy-Deployment & NGen"
- Previous message: Klaus Aschenbrenner: "Finalizer vs. Dispose"
- In reply to: Klaus Aschenbrenner: "Finalizer vs. Dispose"
- Next in thread: Chee Pin Cheam: "Re: Finalizer vs. Dispose"
- Reply: Chee Pin Cheam: "Re: Finalizer vs. Dispose"
- Reply: Brock Allen: "Re: Finalizer vs. Dispose"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 17 Mar 2005 06:08:50 -0800
Hi Klaus Aschenbrenner,
> When should we use a finalizer and when should we implement the
> IDisposable interface? I think when we have the IDisposable interface
> we don't need a finalizer - or are there any scenarios when a
> finalizer is better than implementing the IDisposable interface?
Finalizer and IDisposable are primarily two different things...
If a class implements a finalizer, it will (mostly) be called by the GC if
the object is not used anymore. The finalizer will also be called from
within a different thread...
IDisposable.Dispose is just a normal method!
In general you can say:
Implement IDisposable if you need to free unmanaged resources.
And additionally implement a finalizer if you want to free the unmanaged
resources if the user of your class forgot to call "Dispose".
Mostly all .NET classes which implements IDisposable, also implements an
finalizer.
-- Greetings Jochen My blog about Win32 and .NET http://blog.kalmbachnet.de/
- Next message: Brock Allen: "Re: XCopy-Deployment & NGen"
- Previous message: Klaus Aschenbrenner: "Finalizer vs. Dispose"
- In reply to: Klaus Aschenbrenner: "Finalizer vs. Dispose"
- Next in thread: Chee Pin Cheam: "Re: Finalizer vs. Dispose"
- Reply: Chee Pin Cheam: "Re: Finalizer vs. Dispose"
- Reply: Brock Allen: "Re: Finalizer vs. Dispose"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|