Re: Should the Dispose( ) method only run when there are no other references to an object?

Tech-Archive recommends: Speed Up your PC by fixing your registry



Steve,

It wouldn't. But, as the programmer you would know about other
references and code accordingly for those situations. In other words,
if you allow an object to be used in other threads don't dispose it
until those threads are done with it.

Brian

Steve Richter wrote:
I understand the IDisposable interface and how the using instruction
will call the Dispose method of an object.

What if a reference to an object is passed to a 2nd thread? And the
object contains a handle to an open file. The Dispose( ) method closes
the handle.

How would the Dispose( ) method called from the end of the using block
in the 1st thread know that references to the object still exists in
other threads?

thanks,

-Steve

.



Relevant Pages

  • Re: Memory Leak Experts!!!!
    ... > However as soon as app is restored all this memory is swapped back. ... > DataSet Dispose for example doesn't touch tables and rows. ... > free references in due time. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: events and object lifetime
    ... Not true except for static references. ... No - leaked memory is memory that you could never free even if you could be ... static event subscribers in the same way you think about other objects ... to explicitly dispose of it or it won't be GC'd." ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Disposed forms problem
    ... completely cleaned up until all references to the ... If theForm Is Nothing OrElse theForm.IsDisposed Then ... > The problem is if I close theFrom, then click the button of the calling ... > Even if I call Dispose on the called form when it's closed, ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Memory Leak Experts!!!!
    ... DataSet Dispose for example doesn't touch tables and rows. ... free references in due time. ... survive GCand even worse GCthey tend to stay in memory. ... However as soon as app is restored all this memory is swapped back. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Dispose method
    ... > You always pass around references to objects - you cannot pass an object ... Decide who is going to take responsibility for calling Dispose and ... Doable but very error prone. ... You can use a wrapper class that implements the reference counting (isn't ...
    (microsoft.public.dotnet.languages.csharp)