110,565
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e) {
this.Test();
GC.Collect();
}
private void Test() {
//数据类
ClassC objC = new ClassC();
//向数据类填充数据
objC.InitC();
//销毁数据类里使用的对象
objC.Dispose();
objC = null;
}
class Program
{
private const int maxGarbage = 1000;
static void Main(string[] args) {
//这个时候程序内存占用量是4336k
// Put some objects in memory.
Program.MakeSomeGarbage();
//这个时候程序内存占用量是4428k
// Collect all generations of memory.
GC.Collect();
//这个时候程序内存占用量是4496k
}
static void MakeSomeGarbage() {
Version vt;
for (int i = 0 ; i < maxGarbage ; i++) {
// Create objects and release them to fill up memory
// with unused objects.
vt = new Version();
}
}
}