以下的代码可以释放内存
[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;
}
}
}
这样做来释放内存合适吗/?为什么??

解决方案 »

  1.   

    托管程序是由.Net框架来释放内存的
      

  2.   

    各 位ReduceMemoryFootPrint方法可以产刻释放内存的,而.Net不是马上释放的喔
      

  3.   

    又在自作聪明了,GetProcessWorkingSetSize:了解一个应用程序在运行过程中实际向它交付了多大容量的内存。MinWorkingSet:获取或设置关联进程的允许的最小工作集大小。注意,这不是释放内存!
    注意   请求太大的最小或最大工作集大小时要小心,因为这样做会降低系统性能。真的想释放内存就用GC.Collect