ostapas wrote:You can use RemovePagefaults() procedure from PBOSL lib, not an elegant solution, but usually helps when you have constantly growing memory usage, but have no time or desire to debug it

Since RemovePagefaults() (???) uses EmptyWorkingSet(), afaik this just "visually" hides the problem, if any, resulting in a smaller number in the column "private working set" inside the task manager.
If the memory used by a process grows too much (for a leakage or for legitimate reasons) the OS will remove the less recent used pages from the working set of the process by itself. The pages are moved to a standby list, and are actually cached there (so still in ram) to be given back to the original process if required.
But if the free memory is low and another process is requiring ram to run, the page is actually removed from the cache and the freed ram assigned to the other process working set which actually needs it right now.
EmptyWorkingSet() just does that sooner than later, but does not cure a leakage. The allocated page produced by the leakage is just moved sooner to the standby lists, and consequently the size of the private working set is reported as smaller in the task manager. The ram is still allocated, it's just not listed under the private working set anymore, nothing really changes.
Only
personal satisfaction in seeing a small number.
The only difference is EmptyWorkingSet() will cause a soft page fault if the page is needed again by the original process in order to retrieve it from the standby list, instead of simply having the page already there if enough ram was available.
Worst case can cause an hard page fault if the physical memory associated to the page prematurely moved to the standby list has been assigned to another process, so the original page contents have been swapped out and now the uncached page is requested again by the original process.
In short, I think it can (even if it's unlikely) be detrimental for a program not leaking (swapped pages can legitimately be requested again), and probably irrelevant for a leaking program (those page would be swapped out anyway if and when really needed).
One legitimate application-level use I can think for EmptyWorkingSet() is for a program requiring a lot of resources but for short interval of time.
For example it waits for something to happen, then process a huge amount of data for that event, but the next event is not expected for some time.
It may invoke EmptyWorkingSet() to make available its pages not needed anymore to other programs without the need to wait for the OS to do so.
Maybe this could be an a good idea. Maybe.