[Mono-list] Buggy IDispose handling

Jörg Pommnitz jpo@joerg-pommnitz.de
Thu, 02 Jan 2003 22:14:34 +0100


Hi List,
the following example program from TiC# shows a bug in Mono's handling
of disposable objects inside a using() statement:

//:c05:UsingCleanup.cs
using System;

class UsingCleanup : IDisposable {
  public static void Main(){
    try{
      UsingCleanup uc = new UsingCleanup();
      using(uc){
        throw new NotImplementedException();
      }
    }catch(NotImplementedException){
       Console.WriteLine("Exception ignored");
    }
    Console.WriteLine("Leaving Main( )");
  }

  UsingCleanup(){
    Console.WriteLine("Constructor called");
  }

  public void Dispose(){
    Console.WriteLine("Dispose called");
  }

  ~UsingCleanup(){
    Console.WriteLine("Destructor called");
  }
}///:~

Under Microsoft's .NET runtime I get:

.\UsingCleanup
Constructor called
Dispose called
Exception ignored
Leaving Main( )
Destructor called

while Mono 0.17 results in the following output:
 > mono UsingCleanup.exe
Constructor called
Exception ignored
Leaving Main( )
Destructor called

As you can see, the call to Dispose is missing. This could easily lead 
to a ressource leak.
Is this a known bug or should I file it?

Regards and a successful 2003 for everybody in the Mono team
    Joerg