A question about GC Roots

Questions about YourKit .NET Profiler
Post Reply
roger
Posts: 2
Joined: Tue Jul 14, 2009 10:00 am

A question about GC Roots

Post by roger »

Hi,

In my case, I found a lot of objects in my application with a gc root like "System.Object[1020] [GC Handle]". I guess it means the objects is managed by the gc threads from now on, am I right?
My application's memory's keeping grow slowly, in one day, it growed from 200m to 700 m, and the most hot class is String. There're many object with a gc handle root in my application, does it mean there's something wrong with my application? I used PerfMon to monitor my gen x heap size conunter, and gen 1 size changed often. Is that mean the gc threads had to collect gen 1 every 2 seconds? Is that a bad practice?
Thank you very much.

Besg Regards!
Vladimir Kondratyev
Posts: 1624
Joined: Tue Aug 10, 2004 7:52 pm

Re: A question about GC Roots

Post by Vladimir Kondratyev »

If you see that the number of GC handles is constantly growing in your application, then it's a signal that there is a resource leak in your code. GC handles are used to create handles to managed instances. They act as roots for the garbage collector and can be used to prevent an instance from being collected, to pin a managed instance in memory, or to create a weak reference to an instance. The .NET Framework provides access to GC handles through the System.WeakReference class and the System.InteropServices.GCHandle structure. The runtime also uses GC handles internally to keep track of certain instances, such as managed COM interfaces and static field data.
roger
Posts: 2
Joined: Tue Jul 14, 2009 10:00 am

Re: A question about GC Roots

Post by roger »

Thank you for the reply.
I compared two snapshots, one used 400m process memory, other used 800m. In the comparison, when I view the statistics in class tree, I found the size of <Objecs by classes> only grow 13%, and the objects grow 9%. Does the 13% of size mean that almost all of grown memory usage is allocated by the unmanaged code? Thank you very much!

Best Regards!
Vladimir Kondratyev
Posts: 1624
Joined: Tue Aug 10, 2004 7:52 pm

Re: A question about GC Roots

Post by Vladimir Kondratyev »

Yes, memory leak in native code might be a reason. I'd recommend you to read article http://www.yourkit.com/docs/net40/help/memory_leaks.jsp which describes how to find memory leaks.
Post Reply