Thread handle leak - by Ed Nicholas

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


7
0
Sign in
to vote
ID 430646 Comments
Status Closed Workarounds
Type Bug Repros 2
Opened 4/5/2009 7:45:15 AM
Access Restriction Public

Description

If one creates a thread using a ParameterizedThreadStart delegate and then starts the thread, the thread handle is never garbage collected.  I have verified this behavior on Windows Server 2003 and Windows Server 2008.
Sign in to post a comment.
Posted by masonic82 on 6/18/2012 at 10:49 AM
Same here... Calls to the GC.WaitForPendingFinalizers doesn't appear to be correcting the issue. It seems that each thread after completion and disposal will continue to keep one handle open.    When you have a server application requiring a high number of threads to run constantly throughout the day, these handles really add up quick. Even in the long term, the GC is not collecting them (over days). I've been researching this problem for weeks now for a socket application and it doesn't appear to be anything other than this. Can't even determine any workarounds other than forcing the application to close and reopen periodically (which I'd prefer not to do).
Posted by Mr West on 9/10/2010 at 3:27 AM
Has This handle leakage problem been fixed yet cause I see that rubenhak also questioned the fix last month.
I am currently still seeing the handles leak and the work around does'nt seem to have any impact
Posted by rubenhak on 8/25/2010 at 10:06 AM
yes, I'm also struggling because of this issue. Please let me know where can I obtain the fix from.
Posted by floyd.may on 10/13/2009 at 10:13 AM
This issue is marked as fixed, but I see no reference to which version of the CLR contains the fix. Can someone help?
Posted by Microsoft on 4/8/2009 at 12:39 PM
Thank you for the feedback. I am the threading developer on the Common Language Runtime (CLR) team. The problem you report is a known issue in the CLR, and we are working to fix it in a future release. The problem is that CLR thread handles (and other associated data structures) are cleaned up by the finalizer thread, which normally only runs in response to a garbage collection (GC). If many threads are created and destroyed before a GC occurs (which would be the case if there were few memory allocations in the meantime) then it has the effect of "leaking" handles and memory, althgough these will be reclaimed the next time finalization is triggered. A workaround is to periodically manually trigger finalization, through calls to GC.WaitForPendingFinalizers. As I said, we are working to correct this in a future CLR release.
Posted by Ed Nicholas on 4/7/2009 at 8:20 AM
This is most likely an issue in .Net Framework 3.5 w SP 1 rather than VS 2008.
Posted by Microsoft on 4/5/2009 at 9:54 PM
Thanks for your feedback.

We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you,
Visual Studio Product Team