class Program{ static void Main(string[] args) { Console.WriteLine("Before 1st call TestFunc"); TestFunc(); Console.WriteLine("After 1st call TestFunc"); Console.WriteLine("Before 2nd call TestFunc"); TestFunc(); Console.WriteLine("After 2nd call TestFunc"); Console.ReadLine(); } public static void TestFunc() { List<Employee> empList = new List<Employee>(); for (int i = 1; i <= 50000000; i++) { Employee obj = new Employee(); obj.Name = "fjasdkljflasdkjflsdjflsjfkldsjfljsflsdjlkfajsd"; obj.ID = "11111111111111112222222222222222222222222222222"; empList.Add(obj); } }}public class Employee{ public string Name; public string ID;}我只在一个位置(本地范围)内创建了很多员工,当控件返回主功能时,为什么 DOTNET 不释放内存?假设每个函数调用都使用 1 GB 的内存,在 main 函数结束时,应用程序仍然使用超过 1 GB 的内存。为什么在范围关闭后 GC 不收集?这可能是一个简单的问题,任何帮助都会很棒。
- 1 回答
- 0 关注
- 230 浏览
添加回答
举报
0/150
提交
取消