Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / November 2005

Tip: Looking for answers? Try searching our database.

Garbage collection explosion BEFORE my code executes?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
William Sullivan - 31 Oct 2005 14:41 GMT
I have an extremely weird problem that I have no idea how to approach.  
I have a simple page with a search textbox and a search button.  The button
causes a postback, where I perform the search and display the results in a
DIV that has a tree.  I've tested all the code up until I add in the code for
adjusting the tree in the DIV and it all works fine without problems.  I can
perform the search and put the results in the body of the page and its very
fast.    But when I add in my tree adjustment code, something very strange
happens.
The first time the user clicks on the search button, the OnClick event
immediately fires, I run quickly through my code, and I return the page to
the user with everything displaying how I want.  The SECOND time the button
is clicked, all hell breaks loose.  Watching GC stats in Performance admin
tool, % spent in GC spikes from .08% to around 70%, corresponding to Gen 0
heap size spiking like crazy (minimum value of 262k to max of 5.25m in under
5 seconds), and Gen 0,1 and 2 collections steadily ramping up from around
6000 to 7000 in about 15 seconds.  Everything grinds to a halt until it
settles down.  The freaky thing is that this is happening BEFORE the OnClick
event, and my code, is fired.  After all the craziness calms down is when the
debugger breaks into the OnClick method.  After this point, all my code runs
quickly and the page is returned to the caller.
I've gone through and commented out all of my code in the event handler,
uncommenting line by line until I find the point where this starts to happen.
I've then gone and uncommented all other code, and left this one line
commented to determine if this is what is causing the freakout.  Doing this,
I definitely identified that this method call, if not commented out, causes
the GC to do its freakout.  So, you would think that this one line of code is
where all the trouble is.  The method I'm calling in this line is in an
object I'm doing some much more complex stuff in before and after this line.  
The function is very simple:

public void ExpandTo(TreeNode node)
{
node.Expanded = true;
TreeNode parent = node.Parent;
while(parent != null)
{
parent.Expanded = true;
parent = parent.Parent;
}
}

This tree is only 5 levels deep, so the max number of loops this can execute
is four times (confirmed).  That's only 4-5 TreeNode objects being created
and released,   and they're not much more complex than structs.

My post boils down to two things:  
1)  What the hell is happening here?  I'd have no question if the GC
explosion happened in my code, but it appears to happen before the OnClick
event fires.  Why is the CLR freaking when that one simple function is GOING
to be called?  Why not freak out WHEN its called?
2)  How the heck can I troubleshoot something like this?  ILDASM the DLL to
see what's going on inbetween the button click and my event handler being
fired?
EP - 21 Nov 2005 22:12 GMT
> My post boils down to two things:
> 1)  What the hell is happening here?  I'd have no question if the GC
[quoted text clipped - 3 lines]
> GOING
> to be called?  Why not freak out WHEN its called?

I'd want to know more about when it happens... not on the first click, but
on the 2nd click....
Also, don't try to see where the GC is working while you're stepping through.
Attaching the debugger can really skew performance results and alter when
things might get cleaned up.  I'd suspect alot of that "crazyness" while
you're attached is your debugger hitting a breakpoint and halting everything.
But if it happens exactly the same way when you're not debugging then ignore
me.

> 2)  How the heck can I troubleshoot something like this?  ILDASM the
> DLL to
> see what's going on inbetween the button click and my event handler
> being
> fired?

if you REALLY want to know what's going on under the hood, you can step into
the MSIL (not read, step into)
http://www.geekswithblogs.com/misterp/archive/2005/11/19/60618.aspx

Hello William,

> I have an extremely weird problem that I have no idea how to approach.
> I have a simple page with a search textbox and a search button.  The
[quoted text clipped - 59 lines]
> being created and released,   and they're not much more complex than
> structs.
William Sullivan - 22 Nov 2005 14:45 GMT
Thanks for the reply.  Sorry, but I already figured it out and posted a
followup on another thread, but not on this one.  The problem was my
viewstate.  The search button caused a postback, and my whole tree was being
shipped back to the server.  Not sure exactly where in the process this was
causing all hell to break loose, but disabling viewstate on that control
cleared up the problem.

> I'd want to know more about when it happens... not on the first click, but
> on the 2nd click....
[quoted text clipped - 14 lines]
> the MSIL (not read, step into)
> http://www.geekswithblogs.com/misterp/archive/2005/11/19/60618.aspx

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.