Multiple Snapshots needed to reduce memory in query bee

Memory profiling for .NET developers

Moderators: Luke Jefferson, StephenC, AndrewH, melvyn.harbour, james.billings, Laura Morley, dene.boulton

Multiple Snapshots needed to reduce memory in query bee

Postby mel1daa » Wed Jul 11, 2012 5:02 pm


I am working with the query bee sample and after I close the form and remove the handler to the OnForegrounded event (in the Dispose() event of QueryForm), I take a snapshot. There is no memory drop. I take a second snapshot a few seconds later and the memory drops. I am noticing this with my own application as well - I need to take multiple snapshots to reduce the memory. I was under the impression that after a snapshot is taken, a GC.Collect() was invoked and the memory should drop. Am I doing something wrong?

Posts: 1
Joined: Wed Jul 11, 2012 4:13 pm

Postby jessica.ramos » Thu Jul 12, 2012 10:59 pm

Hi David!

As Andrew's described ( ... php?t=9190), there are a few things that can cause .NET memory usage to appear not to change after a garbage collection:

* The # bytes in all heaps counter is often not accurate as it's only updated after a garbage collection, and there are times when .NET allocates more memory without causing a GC (and rare times when it releases memory outside of a GC). The private bytes counter is updated in real time.

* Fragmentation of the large object heap can prevent .NET from releasing memory back to the system. You can see free space in .NET heaps in the memory profiler, as well as the largest free contiguous block: if there is a lot of free space but the largest contiguous block is small then fragmentation is occurring.

* Objects referenced by objects with finalizers require at least 2 garbage collection cycles to be removed from memory, and possibly more if these references themselves have finalizers.

* .NET can maintain a pool of free memory for future object allocations if it thinks that there will be a lot of them (this allows it to postpone future garbage collections). It might decide to release this back to the system if there is another GC and not much of the free memory is used. This is often beneficial for the performance of server style applications.
Jessica Ramos
Technical Support
Red Gate Software Ltd.
Posts: 235
Joined: Mon Apr 23, 2012 1:13 pm

Return to ANTS Memory Profiler 7

Who is online

Users browsing this forum: No registered users and 0 guests