title: When to call SetProcessWorkingSetSize? (Convincing the memory manager to release the memory)
body: <p>In a previous post ( <a href="https://stackoverflow.com/questions/4463979/my-program-never-releases-the-memory-back-why">My program never releases the memory back. Why?</a> ) I show that FastMM can cache (read as hold for itself) pretty large amounts of memory. If your application just loaded a large data set in RAM, after releasing the data, you will see that impressive amounts of RAM are not released back to the memory pool.  </p>
  
  <p>I looked around and it seems that calling the SetProcessWorkingSetSize API function will "flush" the cache to disk. However, I cannot decide when to call this function. I wanted to call it at the end of the OnClick event on the button that is performing the RAM intensive operation. However, some people are saying that this may cause AV.  </p>
  
  <p>If anybody used this function successfully, please let me (us) know.  </p>
  
  <p>Many thanks. </p>
  
  <hr>
  
  <p>Edit:<br>
  1. After releasing the data set, the program still takes large amounts of RAM. After calling SetProcessWorkingSetSize the size returns to few MB. Some argue that nothing was released back. I agree. But the memory foot print is now small AND it is NOT increasing back after using the program normally (for example when performing normal operation that does not involves loading large data sets). Unfortunately, there is no way to demonstrate that the memory swapped to disk is ever loaded back into memory, but I think it is not.
  2. I have already demonstrated (I hope) this is not a memory leak:<br>
  <a href="https://stackoverflow.com/questions/4463979/my-program-never-releases-the-memory-back-why">My program never releases the memory back. Why?</a><br>
  <a href="https://stackoverflow.com/questions/4475592/how-to-convinde-the-memoery-manager-to-release-unused-memory">How to convince the memory manager to release unused memory</a>  </p>