Re: Disposing. My objects won't destroy

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Sean Hederman (usemy_at_blogentry.com)
Date: 02/17/05


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.



Relevant Pages

  • Re: Object life
    ... it does not destroy the object. ... Collection called the destructor, which is handled by the framework, not by ... Class instances become eligible for Garbage ... IDisposable interface, and Dispose should always be called on such classes, ...
    (microsoft.public.dotnet.general)
  • Re: .NET connection pool problems
    ... Explicit Release of Resources ... the garbage collector frees the object. ... Dispose method that performs the necessary ... Even with this explicit control over resources, the destructor ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Destructors in C#????
    ... A destructor in C# is just a syntax shortcut. ... Finalize on your object. ... non managed resources) that should be released as soon as possible. ... Dispose on it before abandoning any reference to the object. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Managing webservice connections and/or sessions on clint side
    ... Kursat wrote: ... I don't know what the deal is with Dispose() for you. ... If the object itself is being destroyed, then all resources the object is using are released. ... If the object happens to be a Web service object that has been instantiated on the client side, then destroy the object and release all resources the object is using. ...
    (microsoft.public.dotnet.framework.aspnet.webservices)
  • Re: Destroy Objects How ?
    ... you are not required to assign Nothing to an object to 'destroy' it. ... Some classes expose a Dispose method. ... For such objects you need to call the Dispose method of the object rather ... That said, you are free to explicity 'destroy' objects, a'la VB6, if you so ...
    (microsoft.public.dotnet.languages.vb)