[Mono-devel-list] GC doesn't work correctly when using destructors

Friedrich Priewasser priewasser at gmx.at
Thu Apr 22 08:53:57 EDT 2004


Hi

In the following program the garbage collecter doesn't collect anything 
(and so doesn't call the destructor) before the program ends (at the end 
of the program ~T() is called!). Because of this the program needs about 
150 MB RAM while executing. Without the destructor the GC works fine and 
the program needs (allmost) no memory. By the way, calling the GC manually 
changes nothing.


public class Test{
	public static void Main(){
		T t;
		for (int i=0;i<2000000;i++){
			t=new T();
			//if(i%10000==0) System.GC.Collect();
		}
		
		//System.Console.Read();
	}
}

public class T{
	~T(){
		//System.Console.Write("T");
	}
}


Any idea why the GC dosen't free the "T"-objects before shutting down the 
runtime?
	
	Friedrich



More information about the Mono-devel-list mailing list