What does GC.GetTotalMemory really tell us?

  • Thread starter Thread starter Daniel Billingsley
  • Start date Start date
Willy Denoyette said:
I don't think you can load debugger extensions like sos.dll in cordbg , but
I could be wrong.
If you download the latest windbg version, you'll get also the latest and
greatest sos.dll which can be used with version 1.0 and v1.1. Seems like
VS2003 can also load sos.dll, though I never used it. The outdated
documentation of SOS.DLL is included with the sdk "Tool developers guide"
samples, but the online help (!help debugger command) is very detailed and
all you need.
Note: you need to load the sos.dll extension after mscorlib (the CLR) has
been loaded.
There is also a version available through PPS see
http://blogs.msdn.com/mvstanton/archive/2004/04/05/108023.aspx, It looks
like it is the same as the one included with windbg, I've used both without
any problem, but I stick with the windbg version for now.

Thanks for the info. A quick trial with windbg didn't get me very far,
but I might give it another go next time I'm looking at a heap issue.
Certainly looks like one of those tools which takes a while to
understand but which can be incredibly powerful when you know what
you're doing.
 
Jon,

Windbg and friends is extremely powerful, but as always with such tools it's
somewhat complicated to set-up and configure correctly (the path's and
symbol files). Once this is done it takes some time to learn the most
important commands and get at speed, but I don't think there is something
that brings you closer to the internals of a running system than this.

Willy.
 
I don't know what I was thinking there...

A form would include managed and unmanaged resources, right?

Surely while the form is displayed the GC hasn't "cheated" and deallocated
its memory yet as you suggest it might have done with the posted app, right?
And then later when I've clearly closed the form for some time there is no
apparent freeing of memory, at least according to what GetTotalMemory is
reporting. In fact, the memory reported never goes back down and only
continues to climb, even when I just open the same form again.

My first reaction is that if GetTotalMemory is reporting anything remotely
useful then it's an indication of some memory leak in my simple application.

Given that much of your conversation with Willy is deeper than I care to go,
I'd like to just ask the two of you if you would think "leak" if you saw
that behavior (reported allocated memory always rising) from this periodic
reporting of GetTotalMemory upon opening, closing, reopening, and closing
again of a form. Well, let me be clear - by "always rising" I mean never
returning to previous levels when the form is closed.... the results would
be something like (I'm making up the numbers):

2000 - 2600 (open form) - 2100 (close form) - 2700 (open form) - 2250 (close
form) - 2930 (open form) - 2325 (close form)

* I'm predicting Willy's answer will be those numbers don't indicate much
useful, as he's demonstrated with the debug output in my other sample
posting.
 
Daniel Billingsley said:
I don't know what I was thinking there...

A form would include managed and unmanaged resources, right?

A form probably wouldn't include unmanaged resource *directly*,
although it may include references to manages resources which
themselves contain unmanaged resources.
Surely while the form is displayed the GC hasn't "cheated" and deallocated
its memory yet as you suggest it might have done with the posted app, right?
Indeed.

And then later when I've clearly closed the form for some time there is no
apparent freeing of memory, at least according to what GetTotalMemory is
reporting. In fact, the memory reported never goes back down and only
continues to climb, even when I just open the same form again.

And you don't have any other references to it?
My first reaction is that if GetTotalMemory is reporting anything remotely
useful then it's an indication of some memory leak in my simple application.

Quite possibly.
Given that much of your conversation with Willy is deeper than I care to go,
I'd like to just ask the two of you if you would think "leak" if you saw
that behavior (reported allocated memory always rising) from this periodic
reporting of GetTotalMemory upon opening, closing, reopening, and closing
again of a form. Well, let me be clear - by "always rising" I mean never
returning to previous levels when the form is closed.... the results would
be something like (I'm making up the numbers):

How exactly are you closing the form? Are you reopening the *same* form
(in which case you must have a reference to it, so it can't be being
garbage collected) or a new instance of the same type?
2000 - 2600 (open form) - 2100 (close form) - 2700 (open form) - 2250 (close
form) - 2930 (open form) - 2325 (close form)

* I'm predicting Willy's answer will be those numbers don't indicate much
useful, as he's demonstrated with the debug output in my other sample
posting.

That's quite possible. He's clearly rather more of an expert on this
topic than me :)

If the above, when executed several hundred times, however, shows a
continual rise, then it's at least suggestive of something nasty going
on. Could you post the complete app, having simplified it as much as
possible?
 
Jon Skeet said:
A form probably wouldn't include unmanaged resource *directly*,
although it may include references to manages resources which
themselves contain unmanaged resources.

Hmmm. I would have expected there would be some graphics resources like
fonts or windows handles or OS hooks or some such things.
How exactly are you closing the form? Are you reopening the *same* form
(in which case you must have a reference to it, so it can't be being
garbage collected) or a new instance of the same type?

The latter.
If the above, when executed several hundred times, however, shows a
continual rise, then it's at least suggestive of something nasty going
on. Could you post the complete app, having simplified it as much as
possible?

Yes, I had the same thought to see if it eventually starts behaving as
expected.

The application is way too complex, but I'll see if I can duplicate the
behavior in something simple.
 
Just FYI - So far I haven't been able to duplicate the problem behavior with
my simple test, so I'll take a little more critical eye towards a memory
leak within my application when I have a chance.

Thanks for the input though everyone.
 
Back
Top