Skip to content

Instantly share code, notes, and snippets.

@catwarrior
Created October 19, 2016 15:30
Show Gist options
  • Save catwarrior/9f90e116206a7aa117daf7b34f66da0a to your computer and use it in GitHub Desktop.
Save catwarrior/9f90e116206a7aa117daf7b34f66da0a to your computer and use it in GitHub Desktop.
// release any unused pages , making the numbers look good in task manager
///
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool SetProcessWorkingSetSize(IntPtr process,
UIntPtr minimumWorkingSetSize, UIntPtr maximumWorkingSetSize);
public static void ReleaseMemory()
{
// release any unused pages
// making the numbers look good in task manager
// this is totally nonsense in programming
// but good for those users who care
// making them happier with their everyday life
// which is part of user experience
GC.Collect(GC.MaxGeneration);
GC.WaitForPendingFinalizers();
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle,
(UIntPtr)0xFFFFFFFF, (UIntPtr)0xFFFFFFFF);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment