Why need to take several snapshots for a stable image

Memory profiling for .NET developers

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

Why need to take several snapshots for a stable image

Postby charithj » Mon Dec 03, 2012 1:00 am

I have got ANTS Memory Profiler 7.4. If I take a memory snapshot after a certain functionality it shows some memory increase. And then, if I take couple of more memory snapshots (without touching my application) it shows some memory releases and eventually come to a stable no bytes difference screenshot after 2-4 snapshots.

I understand that it does a full garbage cycle before taking a screenshot and do not understand why I need to take a few screenshots in order to get a stable image. I believe this is due to the finalization queue processing?
charithj
 
Posts: 4
Joined: Mon Dec 03, 2012 12:32 am

Postby Brian Donahue » Mon Dec 03, 2012 11:33 am

Yes -- this is a Microsoft GC design issue. ANTS runs GC.Collect on snapshot and if the object requires finalization it is put in the finalizer queue which can take an unknown amount of time before it is finally disposed. Running a second snapshot will clean up the queue because the snapshot command makes ANTS run GC.Collect in such a way that the finalizer queue is cleaned out.
Brian Donahue
 
Posts: 6670
Joined: Mon Aug 23, 2004 10:48 am

Postby charithj » Mon Dec 03, 2012 11:02 pm

Do you use some thing similar to WaitForPendingFinalizers once you call GC.Collect ?

WaitForPendingFinalizers : http://msdn.microsoft.com/en-us/library/system.gc.waitforpendingfinalizers.aspx
charithj
 
Posts: 4
Joined: Mon Dec 03, 2012 12:32 am

Postby Brian Donahue » Tue Dec 04, 2012 10:48 am

Yes; like this:
Code: Select all
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
Brian Donahue
 
Posts: 6670
Joined: Mon Aug 23, 2004 10:48 am

Postby charithj » Tue Dec 04, 2012 11:54 pm

Thanks for your reply Brian!

That all makes sense. Looks like GC's heuristic algorithms make it bit confusing. My initial concern was having some data in Gen0 after getting a screenshot. Now what I am doing is taking some consecutive screenshots until Gen0 becomes zero.

Is there any reason for not calling your below code iteratively until Gen0 becomes zero?

Code: Select all
white (Gen0 byte count > 0)
{
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();   
}


Thanks again for your reply!
charithj
 
Posts: 4
Joined: Mon Dec 03, 2012 12:32 am

Postby Brian Donahue » Wed Dec 05, 2012 10:27 am

You mean you want ANTS to do this, or that you want to put this in your code?
...
I'm afraid I do not know if there is a downside to this, but I can suggest it.
Brian Donahue
 
Posts: 6670
Joined: Mon Aug 23, 2004 10:48 am

Postby charithj » Thu Dec 06, 2012 12:36 am

Being an ANTS user for two years I would like this to be the default behaviour. I cannot see any problem of doing this and I believe that would solve some confusions that fresh users may face. If you could kindly suggest this for your development team that would be really appreciated. I am quite interesting to hear if there is any bad implications of this approach. You have got a very talented developers who knows this area much better than me. I am sorry if I am trying to do something inappropriate here.
charithj
 
Posts: 4
Joined: Mon Dec 03, 2012 12:32 am

Re:

Postby dene.boulton » Mon Dec 10, 2012 2:21 pm

charithj wrote:Thanks for your reply Brian!

That all makes sense. Looks like GC's heuristic algorithms make it bit confusing. My initial concern was having some data in Gen0 after getting a screenshot. Now what I am doing is taking some consecutive screenshots until Gen0 becomes zero.

Is there any reason for not calling your below code iteratively until Gen0 becomes zero?

Code: Select all
white (Gen0 byte count > 0)
{
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();   
}


Thanks again for your reply!


Hello,

Just off the cuff; but one downside I can immediately think of is if the user has 'fixed' a none large object in memory using unsafe & fixed keywords then it would remain in gen0.
Dene Boulton
Red Gate
dene.boulton
 
Posts: 53
Joined: Wed Oct 12, 2011 12:44 pm
Location: Cambridge


Return to ANTS Memory Profiler 7

Who is online

Users browsing this forum: No registered users and 0 guests

cron