Get the program’s memory usage in C#

[memory usage]

This example uses the following code to display information about its memory usage.

// Display information about the current process's memory usage.
private void Form1_Load(object sender, EventArgs e)
    Process proc = Process.GetCurrentProcess();
    AddItem(lvMemory, "Min Working Set",
    AddItem(lvMemory, "Max Working Set",
    AddItem(lvMemory, "Non-paged Memory Size",
    AddItem(lvMemory, "Paged Memory Size",
    AddItem(lvMemory, "Paged System Memory Size",
    AddItem(lvMemory, "Peak Paged Memory Size",
    AddItem(lvMemory, "Peak Virtual Memory Size",
    AddItem(lvMemory, "Peak Working Set",
    AddItem(lvMemory, "Virtual Memory Size",
    AddItem(lvMemory, "Working Set",


The code get the program’s Process object and then uses its properties to learn about its memory usage.

The AddItem method simply adds a new item and subitems to the lvMemory ListView control. The ToFileSize extension method converts a memory size in bytes into a more useful unit such as KB or MB. Download the example and look at the code to see the details.

Download Example   Follow me on Twitter   RSS feed   Donate

This entry was posted in memory, programs and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.