Welcome to MSDN Blogs Sign in | Join | Help

Event Handles “leak”

On our stress run, we saw our process’ handle count steadily increases until certain point, then it stabilizes. However the number of handles is high. Most of those handles are Event handles. We are concerned about it. So we went off and did some investigation.

Turns out the Event handles are coming from the use of Monitor.

When there is contention on the lock object, CLR internally creates an Event handle, presumably to facilitate the thread scheduling. The event handle is not cleaned up until the object is garbage collected.

It appears we were using Monitor in a lot of places, and we had lock contentions, which triggers CLR to allocate a lot of Event handles.

So if you have a lot of long lived objects, be careful about the usage of Monitor.

Published Monday, April 28, 2008 8:00 AM by junfeng
Filed under: ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Microsoft news and tips » Event Handles ???leak???

# re: Event Handles “leak”

Monday, April 28, 2008 5:32 PM by Barry Kelly

Damn! I thought those event handles were multiplexed, only in use while there was contention. That's somewhat disturbing: the events are sticky to the objects once contention triggers event creation.

This seems to demand the creation of some kind of new critical-section-like primitive to prevent handle starvation in the medium term, until the CLR fixes this issue.

# re: Event Handles “leak”

Monday, May 05, 2008 9:53 AM by Lucian Bargaoanu

Interesting. I had the same problem once and I had no idea how to track down those "leaking" events. It would be nice to know how it can be done :). I assumed they were used by some critical sections in unmanaged code.

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker