using System; using System.Diagnostics; using System.Runtime.InteropServices; namespace Binance.TradeRobot.Common.Helpers { /// /// 清理内存 /// public class ClearMemoryHelper { [DllImport("psapi.dll")] static extern int EmptyWorkingSet(IntPtr hwProc); public static void ClearMemory(string processName) { Process[] processes = string.IsNullOrEmpty(processName) ? new Process[] { Process.GetCurrentProcess() } : Process.GetProcessesByName(processName); try { Array.ForEach(processes, p => EmptyWorkingSet(p.Handle)); } catch { throw; } } } }