Reducing Working Set With EmptyWorkingSet

December 7, 2009 04:14 by Anton

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.


Add comment




  Country flag

Click to change captcha
biuquote
  • Comment
  • Preview
Loading