Investigating Memory Usage for Processes
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

Investigating Memory Usage for Processes

If you need to view memory statistics for a process, the Process component provides six memory-usage properties that can be accessed at run time. Each property provides a different statistic for memory allocation.

To investigate memory usage for a process

  1. Bind a process component instance to the process. For more information, see Binding to Existing Processes.
  2. If the property cache needs to be refreshed, call the Refresh method. For more information, see Refreshing Process Component Properties.
  3. Read the memory-usage property you want by referencing the appropriate property.
    PropertyReturns
    PrivateMemorySizeThe number of bytes that the associated process has allocated that cannot be shared with other processes.
    PeakVirtualMemorySizeThe maximum amount of virtual memory that the process has requested.
    PeakPagedMemorySizeThe maximum amount of memory that the associated process has allocated that could be written to the virtual paging file.
    PagedSystemMemorySizeThe amount of memory that the system has allocated on behalf of the associated process that can be written to the virtual memory paging file.
    PagedMemorySizeThe amount of memory that the associated process has allocated that can be written to the virtual memory paging file.
    NonpagedSystemMemorySizeThe amount of memory that the system has allocated on behalf of the associated process that cannot be written to the virtual memory paging file.

The following example shows how to use the Process component to read the PrivateMemorySize property for Notepad and assign the returned property value to NotepadMemory. The value is then displayed in a console. Because Component1(0) is a new instance of the Process component, the property cache does not need to be refreshed.

' Visual Basic 
Dim NotepadMemory as Integer
Dim component1() as Process
component1 = Process.GetProcessesByName("Notepad.exe")
NotepadMemory = component1(0).PrivateMemorySize
Console.WriteLine("Memory used: " & NotepadMemory & ".")

// C#
int memory;
Process[] notepads;
notepads = Process.GetProcessesByName("Notepad.exe");
notepadMemory = notepads[0].PrivateMemorySize;
Console.WriteLine("Memory used: {0}.", notepadMemory);

See Also

Retrieving Information About Processes | Binding to Existing Processes | Introduction to Monitoring and Managing Windows Processes

Show:
© 2016 Microsoft