在需要调用垃圾回收的地方调用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);