June 5, 2003 spout

Ref-Counting + Rotor Status

I just got this email from Chris Tavares (who’s doing the lion’s share of the implementation work to add ref-counting to Rotor):

using System;
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 TestApp {
  public static void Main() {
    for( int i = 0; i < 5; ++i ) LeakAnObj(i);
  }

  static void LeakAnObj( int i ) {
    FinalizerObj obj = new FinalizerObj(i);
  }
}

Under the desktop CLR, I get this:

C:\Home\Chris\Projects\Rotor\src\tests>FinalizerTest
Created Finalizer object 0
Created Finalizer object 1
Created Finalizer object 2
Created Finalizer object 3
Created Finalizer object 4
Finalizing finalizer object 4
Finalizing finalizer object 0
Finalizing finalizer object 3
Finalizing finalizer object 2
Finalizing finalizer object 1
But when I run under Rotor, now I get this:
C:\Home\Chris\Projects\Rotor\src\tests>clix FinalizerTest.exe
Created Finalizer object 0
Finalizing finalizer object 0
Created Finalizer object 1
Finalizing finalizer object 1
Created Finalizer object 2
Finalizing finalizer object 2
Created Finalizer object 3
Finalizing finalizer object 3
Created Finalizer object 4
Finalizing finalizer object 4
Finalizing finalizer object 4
Finalizing finalizer object 0
Finalizing finalizer object 3
Finalizing finalizer object 2
Finalizing finalizer object 1

I obviously still need to figure out how to pull the object off the finalization queue, but that will have to wait until tomorrow night.

Even though they’re being called by us and by the GC, this is the first time we’ve been able to get finalizers working. Wahoo!