I'm trying to create a demo Windows Forms App that does the following:
- Increases the memory working set of the application.
- Programmatically trims the working set.
I have 2 buttons on the form, 1 simulates managed memory usage and the other 1 simulates unmanaged memory usage. I'm not sure if this is the way to increase the working set (the amount of memory you see in Task Manager), but I've started writing it like that (see code example). If you have another way please let me know.
Basically, in my way:
- I'm trying to simulate memory usage (Private Bytes increases as well as Working Set increases).
- Release Private Bytes (via GC or any other way).
- The working set should remain the same (i.e. - even though the memory (private bytes) was released, Task Manager still shows a big chunk of memory reserved for the application).
- At this point, minimizing the application's main window dramatically decreases the working set. I'm trying to programmatically trim the working set by using the "SetProcessWorkingSetSize"
My goal is to create the demo application to show a customer, and I think I've got most of it handled. Just need some help with a few parts:
- I can increase Private Bytes and Working Set, but can't decrease the private bytes.
- I still have to try the SetProcessWorkingSetSize piece of code.
Here are some references:
Public Class Form1
Private objBrushes As List(Of Brush) = New List(Of Brush)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
For i = 0 To 2000
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
For i = 0 To 10000
Dim obj As Brush = New SolidBrush(Color.Blue)