Problem with strange psychic garbage collection freakout!

G

Guest

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?
 
K

Kevin Spencer

Sounds like your "tree" has a lot of HTML in it, and/or a lot of string
manipulation happening on PostBack.
What kind of "tree" are we talking about?
--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
G

Guest

*BUZZ* Wrong! You see the method that causes GC to skyrocket -- BEFORE it
executes -- below. The problem occurrs when the tree has five nodes in it or
five hundred. And, btw, all string manips in my program use SB's, of
course... Try again.
 
D

Damien

William said:
*BUZZ* Wrong! You see the method that causes GC to skyrocket -- BEFORE it
executes -- below. The problem occurrs when the tree has five nodes in it or
five hundred. And, btw, all string manips in my program use SB's, of
course... Try again.
Hi William,

that's not a great way of winning friends or influencing people -
remember, the help you may or may not receive here is *free*.

1) Are you doing anything in the Page_Load?

2) What is the tree? Is it a set of spans you're constructing yourself,
with javascript code to open/close branches, or a third-party control,
or what?

3) My instant suspicion is ViewState - when you've done your first
click (which you say goes through pretty instantly), can you examine
the source in the browser? Is the hidden viewstate field HUGE? If so,
something may be attempting to reconstruct a lot of state before
allowing your event handler to fire. Find it and kill it.

Damien
 
G

Guest

I should have studied my trace before i posted. My tree size explodes when
searching and displaying the results of the search. The size isn't bad on
the backend, but when aspnet attempts to pack the tree into the viewstate and
then deal with it back on the server, it utterly destroys my performance.
Turning off viewstate for the tree div (which I didn't need anyhow; glad it
was on default) solved the problem.

If you're wondering, the tree is in the specs, so I can't do much about it;
I build it dynamically using ajax in order to avoid sending everything at
once.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top