Reducing Working Set With EmptyWorkingSet

If you develop a desktop based application, you’ll notice that the working set size is quite big. For an empty windows form application, the size can be around 20 MB.

While this is not a problem, sometimes you may want to ‘trick’ the user that your running application has low memory consumption. By using P/Invoke this is possible.

[DllImport("psapi.dll")]
static extern int EmptyWorkingSet(IntPtr hwProc);
static void ClearMemory()
{
  try
  {
    EmptyWorkingSet(Process.GetCurrentProcess().Handle);
  }
  catch
  {
  }
}

I got this information from this article. You need to remember that this method will only affect the working set, not the private bytes.