Re: When, why and where should a struct be used?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Bruce Wood wrote:
....
Well, yes, but there's another way that the Dispose method is called,
and that's by the garbage collector just before it reclaims an object.
So, it's not _entirely_ necessary that Dispose be called on an object
before it goes out of scope... it's just better practice because it
releases unmanaged resources sooner. (At least, that's my
understanding... someone please correct me if I'm wrong.)

Is it not Finalize method which is called by GC? To my understanding
(which can also be wrong indeed), GC does not call Dispose, so this is
still necessary to call it somehow. Normally, the call to Dispose is
placed in the object destructor for exactly this very reason: if it
was not called directly, like with 'using', it is guaranteed that it
will be called during garbage collection.
.



Relevant Pages

  • Re: Need explanation on calling Close() from finalizer.
    ... understand is why .NET classes cannot clean up their unmanaged resources ... > NET's Garbage Collector, like you've stated, automated memory management, ... > the Dispose pattern. ... >>> hoping your finalizer will someday be called when the garbage collector ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: events and object lifetime
    ... onto the objects with a direct reference and had a method to set the ... Whether you use Dispose() or some other method name, ... hanging around until your application terminates and a "true" memory ... garbage collector and concentrate on programming your application. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: StatusStrip control leaks its collection items
    ... That's what the garbage collector is for. ... Dispose() on the object when you're done with it. ... WHEN the unmanaged resources get released, or if you need to force ... The finalizer will eventually take care of it as long as ...
    (microsoft.public.dotnet.framework)
  • Re: How to clear controls from a form - Help Needed
    ... some other links I got the impresion that including a dispose method in your ... class modules actually was not needed unless you had some unmanaged resources ... An object that implements Dispose often also implements a Finalizer. ... Finalizer is code that runs when the garbage collector frees the ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Get rid of DataTable
    ... Set it to null + call Dispose on it? ... The garbage collector registers with Windows for low-memory conditions, and will, when needed, start to run more often if some other application needs the memory. ... manual garbage collection but I haven't had to use it in a long time ... since we have decent machines here and I have learned to slim down my ...
    (microsoft.public.dotnet.languages.csharp)