mirror of
https://github.com/snltty/linker.git
synced 2025-10-08 02:20:15 +08:00
38 lines
960 B
C#
38 lines
960 B
C#
using System;
|
|
using System.Diagnostics;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace linker.libs
|
|
{
|
|
public static class GCHelper
|
|
{
|
|
[DllImport("kernel32.dll")]
|
|
public static extern bool SetProcessWorkingSetSize(IntPtr proc, int min, int max);
|
|
public static void FlushMemory()
|
|
{
|
|
try
|
|
{
|
|
GC.RefreshMemoryLimit();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
|
|
GC.Collect();
|
|
GC.Collect(2, GCCollectionMode.Aggressive);
|
|
|
|
GC.SuppressFinalize(true);
|
|
GC.WaitForPendingFinalizers();
|
|
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
|
|
{
|
|
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1);
|
|
}
|
|
}
|
|
public static void Gc(object obj)
|
|
{
|
|
GC.Collect();
|
|
GC.SuppressFinalize(obj);
|
|
}
|
|
}
|
|
}
|