Releasing Nested Objects in Rotor
Chris Tavares is making more progress finishing up the Ref-Counting in Rotor project:
class
FinalizerObj {
int n;
public FinalizerObj( int n ) {
this.n = n;
Console.WriteLine(“Created Finalizer
object {0}”, n);
}
~FinalizerObj() {
Console.WriteLine(“Finalizing finalizer object {0}”, n);
}
}
class
FinalizerContainingObj {
FinalizerObj subObj1;
int n;
FinalizerObj subObj2;
public FinalizerContainingObj( int n ) {
this.n = n;
subObj1 = new
FinalizerObj(n * 100);
subObj2 =
new FinalizerObj((n * 100) + 1);
Console.WriteLine(“Creating containing object {0}”, n);
}
~FinalizerContainingObj( ) {
Console.WriteLine(“Finalizing
finalizer containing obj {0}”, n);
}
}
class
TestApp {
static
void Main() {
for(
int i = 0; i < 5; ++i ) LeakAnObj(i);
}
static void LeakAnObj(int
i) {
FinalizerContainingObj obj =
new FinalizerContainingObj(i);
}
}
Running this app under our ref-counted Rotor yields the following output:
C:\Home\Chris\Projects\Rotor\src\tests>clix FinalizerTest.exe Created Finalizer object 0 Created Finalizer object 1 Creating containing object 0 Finalizing finalizer containing obj 0 Finalizing finalizer object 0 Finalizing finalizer object 1 Created Finalizer object 100 Created Finalizer object 101 Creating containing object 1 Finalizing finalizer containing obj 1 Finalizing finalizer object 100 Finalizing finalizer object 101 Created Finalizer object 200 Created Finalizer object 201 Creating containing object 2 Finalizing finalizer containing obj 2 Finalizing finalizer object 200 Finalizing finalizer object 201 Created Finalizer object 300 Created Finalizer object 301 Creating containing object 3 Finalizing finalizer containing obj 3 Finalizing finalizer object 300 Finalizing finalizer object 301 Created Finalizer object 400 Created Finalizer object 401 Creating containing object 4 Finalizing finalizer containing obj 4 Finalizing finalizer object 400 Finalizing finalizer object 401
In other words, all top-level and 2nd-level objects are finalized deterministically. Wahoo!