为什么微软不封装一下,来释放托管的内存呀/?
以下的代码可以释放内存
[DllImport( "kernel32.dll ")]
public static extern bool GetProcessWorkingSetSize( IntPtr proc, out int min, out int max );
public static void ReduceMemoryFootPrint()
{
int currentMinWorkingSetValue = 0;
int currentMaxWorkingSetValue = 0;
Process currentProcess = Process.GetCurrentProcess();
try
{
if(GetProcessWorkingSetSize(currentProcess.Handle, out currentMinWorkingSetValue, out currentMaxWorkingSetValue))
{
currentProcess.MinWorkingSet = (IntPtr)currentMinWorkingSetValue;
}
}
}
这样做来释放内存合适吗/?为什么??
[解决办法]
又在自作聪明了,GetProcessWorkingSetSize:了解一个应用程序在运行过程中实际向它交付了多大容量的内存。MinWorkingSet:获取或设置关联进程的允许的最小工作集大小。
注意,这不是释放内存!
注意 请求太大的最小或最大工作集大小时要小心,因为这样做会降低系统性能。
真的想释放内存就用GC.Collect