以下的代码可以释放内存
[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;
}
}
}
这样做来释放内存合适吗/?为什么??
[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;
}
}
}
这样做来释放内存合适吗/?为什么??
注意 请求太大的最小或最大工作集大小时要小心,因为这样做会降低系统性能。真的想释放内存就用GC.Collect