Re: GC Handle leaks....
- From: Barry Kelly <barry.j.kelly@xxxxxxxxx>
- Date: Wed, 14 Jun 2006 11:44:33 +0100
"Ollie Riches" <ollie.riches@xxxxxxxxxxxxxxxxx> wrote:
I need some advice on the use of 'Son Of Strike' (sos.dll) and output in
WinDbg.
Note that you can use many features of SOS in VS 2005, without having to
resort to WinDbg. Make sure you're debugging in mixed mode (i.e. enable
unmanaged debugging), and enter your commands (e.g. ".load sos") in the
Immediate window.
Over a period of time I notice in task manager that the 'handles' value had
increased from a starting value of approx. 300 to over 15,000. I use perfmon
to check the .Net memory and related GC counters and the GC Handles for the
process had indeed risen to 15,000.
The handles in Task Manager relates to operating system handles, and are
typically files, directories, registry keys, named pipes, TCP
connections, directories, processes, threads, semaphores and named
events.
Process Explorer from SysInternals.com can help you find out what you're
leaking in this respect.
GC handles are used (AFAIK, and I am not expert at all on this) for
accessing a managed class from unmanaged memory, which would presumably
imply things like:
* keeping an object alive from unmanaged memory (e.g. gcroot<>)
* pinning, to prevent GC from moving a block of memory
* weak references (i.e. the WeakReference class uses GCHandle)
!help gchandles in SOS says this:
"The most common handles are "Strong Handles," which keep the object
they point to alive until the handle is explicitly freed. "Pinned
Handles" are used to prevent the garbage collector from moving an object
during collection. These should be used sparingly, and for short periods
of time. If you don't follow that precept, the gc heap can become very
fragmented."
From the dump of this I can see that I have forgotten to call Dispose on a
System.Threading.Timer object. So I implement a fix and patch the server
accordingly. When implementing the fix I review the code and make sure that
all Dispose methods are called accordingly (using 'using' :)).
Make sure you're calling Dispose() for pretty much everything that
implements IDisposable: this include FileStreams, WaitHandles, Forms,
etc. Garbage collection is a memory manager, not a resource manager.
After monitoring the process for another couple of days I see that the
'handles' value in task manager has risen but by not as much approx 3,500
BUT using perfmon I see that the GC Handles has stayed constant and seems to
now exhibit 'normal' behaviour.
I re-ran 'Son Of Strike' with command parameter '!sos.objsize' and I am
still seeing a lot of entries System.Threading.Timer.
HANDLE(Strong):6d1cd8: sizeof(00ec194c) = 920 ( 0x398) bytes
(System.Threading.TimerCallback)
HANDLE(Strong):6d1cec: sizeof(00ebffac) = 920 ( 0x398) bytes
(System.Threading.TimerCallback)
HANDLE(Strong):6d1cf4: sizeof(00ebfde4) = 920 ( 0x398) bytes
(System.Threading.TimerCallback)
HANDLE(Strong):6d1d08: sizeof(00ebf718) = 920 ( 0x398) bytes
(System.Threading.TimerCallback)
etc....
Is this still an issues?
If it's not leaking, and the working set isn't growing, and performance
isn't degrading, then I would say that it isn't a problem.
Are the callbacks still being called? What does the tail end of
!dumpheap -stat
say? And are these objects being kept alive because of these handles? In
other words, are a significant amount of your resources being consumed
by this?
What does 'HANDLE(Strong)' mean in this respect?
It means the GCHandle doesn't permit the object to be collected. For
example, WeakReference's use of GCHandle would be weak, because the
whole purpose of the class is to keep a reference but also allow the
target object to be collected. (In fact, WeakReference uses "weak short"
handles; I don't know the difference between weak short and weak long
handles.)
Does the 'handles' value in task manager have any real meaning in .Net or
relation to .Net GC Handles?
No.
-- Barry
--
http://barrkel.blogspot.com/
.
- Follow-Ups:
- Re: GC Handle leaks....
- From: Barry Kelly
- Re: GC Handle leaks....
- References:
- GC Handle leaks....
- From: Ollie Riches
- GC Handle leaks....
- Prev by Date: GC Handle leaks....
- Next by Date: Re: GC Handle leaks....
- Previous by thread: GC Handle leaks....
- Next by thread: Re: GC Handle leaks....
- Index(es):
Relevant Pages
|