[Mono-devel-list] About some object-drop actions (Finalizers and IDisposable)

yoros at wanadoo.es yoros at wanadoo.es
Tue Dec 2 00:34:08 EST 2003


On Tue, Dec 02, 2003 at 12:22:17PM +1100, Chris Masters wrote:
> Would a C# using block acheive what you want? It calls dispose on the object
> you specify upon exiting the using block. Or is this still too dependant on
> the client for you?
> 
> using System;
> 
> public class App
> {
>      public static void Main()
>      {
>          using (SomeClass s = new SomeClass())
>          {
>               s.HelloWorld();
>          }
>      }
> }
> 
> public class SomeClass : IDisposable
> {
>      public void HelloWorld()
>      {
>          Console.WriteLine("Hello World!");
>      }
>      public void Dispose()
>      {
>          Console.WriteLine("disposing!");
>      }
> }
> 
> GC.Collect would do it I suppose, but is bad to do explicitly in the .NET
> framework as it promotes objects to the next gen if they aren't collectable,
> but I guess thats not an issue in Mono since its not a generational GC atm.
> 

But using IDisposable you should call s.Dispose() from the client side.
I think I can't do what I want (finalizers "must" be called before
freeing an object but that's not ensured... :(

Regards,

    Pedro

-- 
Pedro Martínez Juliá
\  yoros at terra.es
)|    yoros at wanadoo.es
/        http://yoros.dyndns.org
Socio HispaLinux #311
Usuario Linux #275438 - http://counter.li.org
GnuPG public information:  pub  1024D/74F1D3AC
Key fingerprint = 8431 7B47 D2B4 5A46 5F8E  534F 588B E285 74F1 D3AC



More information about the Mono-devel-list mailing list