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 / Languages / C# / May 2007

Tip: Looking for answers? Try searching our database.

Confused about memory usage.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Frank Rizzo - 30 May 2007 18:24 GMT
I have an application (windows service) that in the beginning reads data
rapidly into a collection of large object trees.  Each object tree in
the collection is about 100mb and typically there are 6-20 object trees
in the collection.  When the application starts and the data is being
read in, I watch the memory generations via the Process Explorer
(basically .NET CLR Memory perf counters).  What I see is a bit
confusing.  Most of the memory gets promoted from Gen0 to Gen2 to Gen2
(and to the Large Object Heap) in a fairly fast succession.  When all
the database information has been read in, the memory usage settles in
the following numbers.

Gen0 1,048,576
Gen1 67,044
Gen2 571,410,644
LOH  71,653,000

Then after about 10 minutes of that I attempt to dump the memory by
setting all the root object to null, followed by GC.Collect() and
GC.WaitForPendingFinalizers().

foreach obj in collection
{
    obj.Dispose();
    obj = null;

    print ("Before " + GC.GetTotalMemory(false).ToString());
    GC.Collect();
    GC.WaitForPendingFinalizers();
    print ("After " + GC.GetTotalMemory(true).ToString());
}

The root objects are collected, this I know, because the finalizers
write stuff to the log.  Now the memory looks like this:

Gen0 1,048,576
Gen1 2,940
Gen2 518,267,836
LOH  71,556,328

So basically, Gen2 decreased a bit, while none of the other Generations
changed much.

In addition, I check the memory usage via GC.GetTotalMemory method.
Before the first object is collected, it reports memory usage at
506,804,036.  With every GC.Collect()/GC.WaitForPendingFinalizers()
call, the value decreases by about 5-10mb.  After the final GC is
forced, the memory is reported at 435,156,904.  I am not sure where this
 number comes from, but it does not jive with what is being shown from
perfmon.

So I have a couple of questions here:

1.  Given that my root node gets collected, why does the memory usage
not decrease.

2.  Where does GC.GetTotalMemory get its numbers from and why do they
not match with what's in the heap.

3.  Where do I go from here as far as debugging the memory leak (other
than SOS)?

Regards
Frank Rizzo - 31 May 2007 06:43 GMT
Never mind.  One call to MS Support and a lesson in WinDbg/SOS debugging
techniques located my bug.

> I have an application (windows service) that in the beginning reads data
> rapidly into a collection of large object trees.  Each object tree in
[quoted text clipped - 58 lines]
>
> Regards

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.