I've asked a question about my memory management problem in WPF, but this is a different one about the same problem. I am using DotTrace trying to figure out what's going on. When I start up my app, I can see in Task Manager that it is taking 200MB. DotTrace says a total of 33MB. If I simply minimize the window and bring it back up, the memory footprint according to TM is about 25MB.
I have a ListBox that shows peoples names and pictures. It shows up to 3000 people (I will work on paging, but that's not the point here). As I scroll down, I can see in TM that the memory increases rapidly. If I just keep scrolling up and down memory quick gets to 1GB. During the scroll there are no changes to the underlying data and there are no events of my own. If I minimize the window and bring it back up, memory drops from 1GB to 25MB.
Before minimizing and seeing the memory go down in TM I took a snapshot with DotTrace and it shows the same amount of memory as before the scrolling - around 30MB or so.
Can someone please explain to me what happens to memory when the app is minimized? Is the figure shown in Task Manager to be trusted?
Thanks
PS1: There's no change in behavior if I do or don't add this to my ListBox:
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.VirtualizationMode="Recycling"
PS2: I've put a button with the code, and the GC doesn't reclaim much if anything(it drops from, say 700MB to 680MB):
GC.Collect();
GC.WaitForPendingFinalizers();