标签:
* 这个程序非常巧妙的探测了一下垃圾回收机制,发现如下结论:
* 当内存紧急时,才会启动垃圾回收GC.Collect()
* 从此程序的运行上来看,delete是连续出现的,这体现了垃圾回收的强度。
* new haha()这种东西确实是垃圾,会被回收的(除非它有timer,这个对象被另一个线程占用)
using System;
using System.Windows.Forms;
using System.Threading;
class haha
{
int[] a=new int[10000000];
haha()
{
Console.WriteLine("created");
}
void run()
{
Console.WriteLine("i am running");
}
~haha()
{
Console.WriteLine("deleted");
}
static void Main(){
for (int i = 0; i < 100; i++)
{
new haha().run();
GC.Collect();
}
Application.Run();
}
}
标签:
原文地址:http://www.cnblogs.com/weidiao/p/4936484.html