有人告诉我GC.GetTotalMemory(false)和GC.GetTotalMemory(true)之间的区别。GC.GetTotalMemory(false)和GC.GetTotalMemory(true)之间的区别是什么
我有一个小程序,当我比较结果时,第一个循环 给出了放置放<循环计数0 Diff = 32> for GC.GetTotalMemory(true);对于GC.GetTotalMemory(false),为 和<循环计数0 Diff = 0>; 但它不应该是另一回事?
其余的循环会打印一些数字,这两种情况都不相同。这个数字表示什么?为什么它随着循环的增加而变化。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace test
{
struct Address
{
public string Street;
}
class Details
{
public string Name ;
public Address address = new Address();
}
class emp :IDisposable
{
public Details objb = new Details();
bool disposed = false;
#region IDisposable Members
public void Dispose()
{
Disposing(true);
}
void Disposing(bool disposing)
{
if (!disposed)
disposed = disposing;
objb = null;
GC.SuppressFinalize(this);
}
#endregion
}
class Program
{
static void Main(string[] args)
{
long size1 = GC.GetTotalMemory(false);
emp empobj = null;
for (int i = 0; i < 200;i++)
{
// using (empobj = new emp()) //------- (1)
{
empobj = new emp(); //------- (2)
empobj.objb.Name = "ssssssssssssssssss";
empobj.objb.address.Street = "asdfasdfasdfasdf";
}
long size2 = GC.GetTotalMemory(false);
Console.WriteLine("loop count " +i + " Diff = " +(size2-size1));
}
}
}
}
完整垃圾回收... – Peter 2010-04-06 06:13:03
在当我通过真实的情况下,我预期得到差异= 0,因为方法等待垃圾收集。 但是当我通过false时,我得到了diff = 0,这让我感到困惑 – somaraj 2010-04-06 06:28:43