Page 1 of 1

2 snapshots required

Posted: Thu Aug 15, 2013 12:42 am
by Dave
Attached is a real-time plot of total bytes. In it, I performed the same action 3 times. After each action, I collected 2 heap snapshots. As you can see, I got part of the memory back after the first snapshot and the rest back after the second snapshot.

Why do I need two heap snapshots to get the memory back? Assuming its something in my code, do you have any tips on how to identify what is keeping the memory from being collected after the first heap snapshot?

Thanks in advance!

Re: 2 snapshots required

Posted: Thu Aug 15, 2013 3:37 pm
by Andreas Suurkuusk
I believe that you have references that are not released immediately after you perform the action. Maybe you have instances that are stored in a cache that gets cleared after a while, or in a session that expires.

If you compare the two snapshots you should be able to find types with a negative delta value for live instances and live bytes. After you have identified types with a negative delta, you can select the first snapshot and hopefully you will be able to identify the instances that exists in the first snapshot but not the second. Unfortunately it is not possible to retrieve information about specific removed instances, since the profiler only presents a count of removed instances. This is something we might improve in a future version.

Re: 2 snapshots required

Posted: Thu Aug 15, 2013 8:34 pm
by Dave
I found part of my problem. Apparently when you add an array of objects to a ListBox, it caches the objects in an 'entries' member even after you call Clear(). Calling Clear() will set the number of items to 0, but the cached objects will remain. However, if you call <ListBox>.Items.RemoveAt(index) it will remove the objects from the entries.