The problem comes with derivation. Because you have derivation, you
don't know at the point of the reference whether you are holding onto an
object that requires ref counting or not. You only know whether the
compile-time type supported ref-counting, but due to object orientation
and polymorphism, the compile-time type may be different from the
run-time type.

Suppose you have:

// I don't care about reference counting for this class
class B {
}

class X {
  B b;

  public void foo(B b) {
     this.b = b;
  }

  public void bar() {
     this.b = null;
  }
}

Does class X do reference counting / ownership tracking on field b? 

If not, what happens when this following class comes along:

[reference counted / ownership tracked]
class C: B, IDisposable
{
   ...
}

If we create an instance of reference counted class C, and pass it to
X.foo, then the reference counting/ownership is lost, and the instance C
will not be finalized/disposed at the correct time (when bar is called).

If class X does do reference counting / ownership tracking on field b,
then you've essentially adopted the position that reference counting /
ownership tracking must be done on all objects.

-----Original Message-----
From: Mark Burns [mailto:mburns@;QUIXNET.NET] 
Sent: Wednesday, November 06, 2002 8:23 AM
To: [EMAIL PROTECTED]
Subject: Re: [ADVANCED-DOTNET] Enforcing IDisposable ownership rules

Chris,

> Unfortunately, you have to ref-count every object, because top-level
> objects may have no finalizer, but objects they hold might, or objects
> that are held by those objects (etc).

This statement does not make sense to me. I picture handling the
refcounting sematics as an on-the-fly (well, on-the-compile, anyway)
custom-generated adapter class type of model. Why would you have any
overhead on objects that you don't need the on-the-fly code generation
for?

Hmm...another difference is that I don't see the .dispose pattern going
away, but retaining it as an essential part of the system, but
automating it in behind-the-scenes goo. This is a different model than
you've been considering, I think.

Regards,
Mark Burns

PS. Weren't you going to be putting out a progress report update on your
project a while back? <poke, prod>  :-)

You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to