在一个程序中打开很多Form,程序的内存持续增加
但是我在关闭这些Form后内存并没有减少。
1. 应该Form中的一些控件占用的内存, 请问如何在关闭Form后释放掉这些内存
2. 是否需要手动给Form中的每个控件在窗体关闭事件中添加Control.Dispose()?
3. GC会不会自动回收这些内存?NET内存
但是我在关闭这些Form后内存并没有减少。
1. 应该Form中的一些控件占用的内存, 请问如何在关闭Form后释放掉这些内存
2. 是否需要手动给Form中的每个控件在窗体关闭事件中添加Control.Dispose()?
3. GC会不会自动回收这些内存?NET内存
GC.Collect();
//Use this method to try to reclaim all memory that is inaccessible.
using System;
using System.Collections.Generic;
namespace nnn
{
class ppp
{
static void Main()
{
sss();//制造垃圾
Console.WriteLine(GC.GetTotalMemory(false)); //结果,输出 8029468
GC.Collect(); //收集垃圾
Console.WriteLine(GC.GetTotalMemory(true)); //结果,输出 30812
} static void sss()
{
List<DateTime> ppp = new List<DateTime>(999999);
for (int i = 0; i < ppp.Capacity; i++)
{
ppp.Add(DateTime.Now);
}
}
}
}