[Mono-dev] GC.Collect() CLR<>Mono difference.

Lucas Meijer lucas at lucasmeijer.com
Thu Jan 8 11:33:58 EST 2009


Here's another one.  (Unsure if these are considered ontopic. If not, 
please let me know)

This small test program shows GC.Collect() + WeakReference working 
different on CLR
than they do on Mono. In mono, the WeakReference is still alive after 
GC.Collect(),
in the clr, the WeakReference is no longer active.

using System;

public class MonoTest2
{
    public static void Main()
    {
        var obj = new Version();
        WeakReference reference = new WeakReference(obj);
        obj = null;
        GC.Collect();
        Console.WriteLine("reference.IsAlive: " + reference.IsAlive);
        //mono outputs true
        //clr outputs false
    }
}


If people think this is a a bug, I'll file a report.

Bye, Lucas


More information about the Mono-devel-list mailing list