I've been scratching my head for days trying to figure this out, but can anyone explain why even a simple application seems to hold on to resources after (supposedly) releasing them?
To duplicate specifically, create a new windows application project and add two forms. On Form1 put a button and in the button's click event put the following code:
Dim f As New Form2
f.ShowDialog()
f = Nothing
Step 1. Start the app.
Step 2. Check memory usage at this point in Task Manager. In my case, it shows about 15,920.
Step 3. Now click Button1 which will pop open Form2.
Step 4. Check memory usage again. In my case, it shows about 16,416 - a slight increase which is expected.
Step 5. Now close Form2.
Step 6. Check memory usage.
One would ***expect*** that now that Form2 has been closed and set to nothing, memory usage would return to the level it was before Form2 opened.
However, memory usage has not gone down at all - in fact, it has increased slightly! Why? Why? Why? And if you continue to open and close Form2, memory usage climbs each time.
Makes no sense.
To further confuse things further, do this:
After step 2 (before clicking the button), MINIMIZE Form1.
Wow - memory usage drops to 728k!
Now restore the window.
You would ***expect*** that memory usage would go back up to the level it was before the window was minimized.
However, memory usage now has dropped to around 2,496!
This again makes no sense. Why would Simply minimizing and restoring a form vastly decrease memory usage?
Now more importantly, is there a way to reclaim memory when completely closing a form?
Any experts out there with a solid answer?
Thanks,
Dean
To duplicate specifically, create a new windows application project and add two forms. On Form1 put a button and in the button's click event put the following code:
Dim f As New Form2
f.ShowDialog()
f = Nothing
Step 1. Start the app.
Step 2. Check memory usage at this point in Task Manager. In my case, it shows about 15,920.
Step 3. Now click Button1 which will pop open Form2.
Step 4. Check memory usage again. In my case, it shows about 16,416 - a slight increase which is expected.
Step 5. Now close Form2.
Step 6. Check memory usage.
One would ***expect*** that now that Form2 has been closed and set to nothing, memory usage would return to the level it was before Form2 opened.
However, memory usage has not gone down at all - in fact, it has increased slightly! Why? Why? Why? And if you continue to open and close Form2, memory usage climbs each time.
Makes no sense.
To further confuse things further, do this:
After step 2 (before clicking the button), MINIMIZE Form1.
Wow - memory usage drops to 728k!
Now restore the window.
You would ***expect*** that memory usage would go back up to the level it was before the window was minimized.
However, memory usage now has dropped to around 2,496!
This again makes no sense. Why would Simply minimizing and restoring a form vastly decrease memory usage?
Now more importantly, is there a way to reclaim memory when completely closing a form?
Any experts out there with a solid answer?
Thanks,
Dean