C# 强制GC垃圾回收


在需要调用垃圾回收的地方调用ClearMemory()

public static void ClearMemory()
{
    GC.Collect();
    GC.WaitForPendingFinalizers();
    if (Environment.OSVersion.Platform == PlatformID.Win32NT)
    {
        SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
    }
}

[DllImport("kernel32.dll")]
public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM