Re: Disposing. My objects won't destroy
From: Sean Hederman (usemy_at_blogentry.com)
Date: 02/17/05
- Next message: Willy Denoyette [MVP]: "Re: Authenticate agains several Active Directory Domains"
- Previous message: Nicholas Paldino [.NET/C# MVP]: "Re: throws keyword missing in C#"
- In reply to: Claire: "Re: Disposing. My objects won't destroy"
- Next in thread: Sean Hederman: "Re: Disposing. My objects won't destroy"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 17 Feb 2005 17:12:24 +0200
Unlike many other environments .NET does not have deterministic
finalization. Your objects are not neccesarily destroyed when all references
to them are released. That is simply the earliest possible time at which
they can be destroyed. The .NET Garbage Collector will decide when to
destroy your objects, and the destructor will be called then. This is why we
have Dispose, to ensure that expensive resources like database connections
and handles can be closed at a predictable and early time.
For managed resources it is generally unneccesary to implement both a
destructor and a Dispose method. For unmanaged resources see this
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconimplementingdisposemethod.asp
for some reccommendations.
"Claire" <cc@hotmai1.com> wrote in message
news:37j0gmF5eo805U1@individual.net...
>> I've also got a class destructor in addition to a dispose. I don't
>> actually use it because my cleanup code is in the Dispose() method but I
>> notice that the breakpoint I placed in there wasn't getting called (code
>> line I added to destructor for testing was timer = null) So how can I be
>> sure my object has been destroyed?
>
> I noticed that the final destructor only got called when the application
> terminated. As I'd created/disposed of several instances of the object
> during the course of running the app, there were several breaks in the
> destructor right at the end. So something still isn't right.
- Next message: Willy Denoyette [MVP]: "Re: Authenticate agains several Active Directory Domains"
- Previous message: Nicholas Paldino [.NET/C# MVP]: "Re: throws keyword missing in C#"
- In reply to: Claire: "Re: Disposing. My objects won't destroy"
- Next in thread: Sean Hederman: "Re: Disposing. My objects won't destroy"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|