Re: Should the Dispose( ) method only run when there are no other references to an object?
- From: "Steve Richter" <StephenRichter@xxxxxxxxx>
- Date: 21 Jan 2007 19:58:05 -0800
Brian Gideon wrote:
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.
thanks for confirming that. I can accept that I have to program for it.
I am thinking that the absence of reference counting from .NET objects
is a failing of its design. Can I define a ReferenceCountObject class
that is derived from Object. Then base any class of mine that I want to
maintain a reference count in from that class? How would such a class
work to update the reference count when the object is passed by
reference to a method or added to a list?
-Steve
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
.
- Follow-Ups:
- References:
- Prev by Date: Re: << and >> operators in c#
- Next by Date: Re: << and >> operators in c#
- Previous by thread: Re: Should the Dispose( ) method only run when there are no other references to an object?
- Next by thread: Re: Should the Dispose( ) method only run when there are no other references to an object?
- Index(es):
Relevant Pages
|