Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

EmptyWorkingSet (psapi)
 
.
Summary
EmptyWorkingSet wherever possible moves an applications pages from RAM to the page file, therefore freeing physical RAM. Good for giving you a bit more memory for the programs you need when Windows doesn't free up memory from something that has been sitting idle for hours.

EpicAndrew is an Epic Idiot!

C# Signature:

[DllImport("psapi")]
public static extern bool EmptyWorkingSet(long hProcess);

VB Signature:

'Sorry - not tested yet

User-Defined Types:

None.

Alternative Managed API:

System.Diagnostics.Process.MaxWorkingSet and System.Diagnostics.Process.MinWorkingSet are similar but are used to set thresholds rather than just free whatever can be freed.

Notes:

Tips & Tricks:

Please add some!

Sample Code:

    public static bool TrimWSByProcess(Process process)
    {
        bool _result = false; //assume failed

        try
        {
            if (process != null)
            { //only continue if we have a process
                long _workingSet = process.WorkingSet64;

                //trim working set
                _result = PsapiHelper.EmptyWorkingSet((long)process.Handle);

                //check result
                if (_result)
                { //sucessfully trimed

                }
                else
                { //failed to trim

                }
            }
            else
            { //no process passed in

            }
        }
        catch (Exception ex)
        { //exception occured. Do some error handling
            _result = false;
            throw; //throw the error in this case.
        }

        return _result;
    }

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Find References
Show Printable Version
Revisions