Re: Garbage collection explosion BEFORE my code executes?



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?

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
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.



.