[Mono-list] Finalize()

Weiqi Gao weiqigao@networkusa.net
11 Oct 2002 22:44:33 -0500


The following snippet:

==========8<==========8<==========8<==========8<==========
class Foo {
  protected override void Finalize() {
    try {
      System.Console.WriteLine("Foo::Finalize()");
    } finally {
      base.Finalize();
    }
  }
}

class Bar : Foo {
  protected override void Finalize() {
    try {
      System.Console.WriteLine("Bar::Finalize()");
    } finally {
      base.Finalize();
    }
  }
}

class Test {
  static void Main() {
    new Bar();
  }
}
==========8<==========8<==========8<==========8<==========

compiles under mcs but generates an error under csc.  The mcs generated
binary runs and gives this result:

==========8<==========8<==========8<==========8<==========
Bar::Finalize()
Foo::Finalize()
Foo::Finalize()
==========8<==========8<==========8<==========8<==========

Instead of generating a "You should not override object.Finalize()"
error message as csc does, mcs not only compiles the method, but also
add a call to base.Finalize() in the body of Finalize() in a finally
block.

Is this the desired behavior?

-- 
Weiqi Gao
weiqigao@networkusa.net