How to: Investigate 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 How to: Bind to Existing Processes.

  2. If the property cache needs to be refreshed, call the Refresh method. For more information, see How to: Refresh Process Component Properties.

  3. Read the memory-usage property you want by referencing the appropriate property.

    Property

    Returns

    PrivateMemorySize64

    The number of bytes that the associated process has allocated that cannot be shared with other processes.

    PeakVirtualMemorySize64

    The maximum amount of memory that the associated process has allocated that could be written to the virtual paging file.

    PagedSystemMemorySize

    The amount of memory that the system has allocated on behalf of the associated process that can be written to the virtual memory paging file.

    PagedMemorySize

    The amount of memory that the associated process has allocated that can be written to the virtual memory paging file.

    NonpagedSystemMemorySize

    The 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 PrivateMemorySize64 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.

    Dim NotepadMemory As Long 
    Dim component1() As Process
    component1 = Process.GetProcessesByName("Notepad.exe")
    NotepadMemory = component1(0).PrivateMemorySize64
    Console.WriteLine("Memory used: " & NotepadMemory & ".")
    
    long memory;
            Process[] notepads;
            notepads = Process.GetProcessesByName("Notepad.exe");
            memory = notepads[0].PrivateMemorySize64;
            Console.WriteLine("Memory used: {0}.", memory);
    

See Also

Tasks

How to: Bind to Existing Processes

Concepts

Introduction to Monitoring and Managing Windows Processes

Other Resources

Retrieving Information About Processes