Red Gate forums :: View topic - Why need to take several snapshots for a stable image
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
ANTS Memory Profiler 7
ANTS Memory Profiler 7 forum

Why need to take several snapshots for a stable image

Search in ANTS Memory Profiler 7 forum
Post new topic   Reply to topic
Jump to:  
Author Message
charithj



Joined: 03 Dec 2012
Posts: 4

PostPosted: Mon Dec 03, 2012 1:00 am    Post subject: Why need to take several snapshots for a stable image Reply with quote

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?
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6577

PostPosted: Mon Dec 03, 2012 11:33 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
charithj



Joined: 03 Dec 2012
Posts: 4

PostPosted: Mon Dec 03, 2012 11:02 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6577

PostPosted: Tue Dec 04, 2012 10:48 am    Post subject: Reply with quote

Yes; like this:
Code:
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();
Back to top
View user's profile Send private message
charithj



Joined: 03 Dec 2012
Posts: 4

PostPosted: Tue Dec 04, 2012 11:54 pm    Post subject: Reply with quote

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:
white (Gen0 byte count > 0)
{
            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.Collect();   
}


Thanks again for your reply!
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6577

PostPosted: Wed Dec 05, 2012 10:27 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
charithj



Joined: 03 Dec 2012
Posts: 4

PostPosted: Thu Dec 06, 2012 12:36 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
dene.boulton



Joined: 12 Oct 2011
Posts: 53
Location: Cambridge

PostPosted: Mon Dec 10, 2012 2:21 pm    Post subject: Re: Reply with quote

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:
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
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group