Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLearn about a program's memory usage in Visual Basic .NET
DescriptionThis example shows how to learn about a program's memory usage in Visual Basic .NET.
Keywordsmemory, working set, memory usage, Visual Basic .NET, VB.NET
CategoriesSoftware Engineering, Files and Directories
 

This example uses the following code to get information about the program's memory usage.

 
' Display information about the current process's memory
' usage.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    Dim proc As Process = Process.GetCurrentProcess()
    AddItem(lvMemory, "Min Working Set", _
        (CDbl(proc.MinWorkingSet).ToFileSize()))
    AddItem(lvMemory, "Max Working Set", _
        (CDbl(proc.MaxWorkingSet).ToFileSize()))
    AddItem(lvMemory, "Non-paged Memory Size", _
        (CDbl(proc.NonpagedSystemMemorySize64).ToFileSize()))
    AddItem(lvMemory, "Paged Memory Size", _
        (CDbl(proc.PagedMemorySize64).ToFileSize()))
    AddItem(lvMemory, "Paged System Memory Size", _
        (CDbl(proc.PagedSystemMemorySize64).ToFileSize()))
    AddItem(lvMemory, "Peak Paged Memory Size", _
        (CDbl(proc.PeakPagedMemorySize64).ToFileSize()))
    AddItem(lvMemory, "Peak Virtual Memory Size", _
        (CDbl(proc.PeakVirtualMemorySize64).ToFileSize()))
    AddItem(lvMemory, "Peak Working Set", _
        (CDbl(proc.PeakWorkingSet64).ToFileSize()))
    AddItem(lvMemory, "Virtual Memory Size", _
        (CDbl(proc.VirtualMemorySize64).ToFileSize()))
    AddItem(lvMemory, "Working Set", _
        (CDbl(proc.WorkingSet64).ToFileSize()))

    lvMemory.Columns(0).AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent)
    lvMemory.Columns(1).AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent)
End Sub
 
The program uses the Process class's GetCurrentProcess method to get the current process. It then uses that object's properties to learn about the memory usage.

The AddItem subroutine adds an item to the program's ListView control.

 
' Add an item to the ListView.
Private Sub AddItem(ByVal lv As ListView, ByVal item_name As _
    String, ByVal item_value As String)
    Dim lv_item As ListViewItem = lv.Items.Add(item_name)
    lv_item.SubItems.Add(item_value)
End Sub
 
 
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated