I currently debug a multi threaded application, which runs without errors until some functions where called about 2000 times. After that the application stops responding, which I could track down to _beginthreadex failing with an out of memory error.
When examining the Application in ProcessExplorer I can see a growing number of thread handles leaked and a growing virtual memory until the error occurs, the private bytes stay low. The leaked threads also call CoInitialize and never call CoUninitialize.
What I would like to know is:
- What does the Virtual memory represent ?
- Is the virtual memory related to the leaked thread handles?
- Does COM or MSXML6 (called by the threads) copy thread handles and how can I Close them?
I hope that my question is clear and doesn t break any roules,it is my first question and english isn t my first language.:-(
I forgot to mention, I close the handles returned by _beginthreadex once the threads get terminated, which reduces the number of open handles by about half but does not affect the virtual memory. Additionally before i inserted the CloseHandle call each thread handle shown in ProcessExplorer had a handle count of two for the thread.
Edit
I fell stupid for not including this before, I know that the threads exit as the number of active threads while debugging with visual studio does not grow. And I do hope that not all of the leaked memory is a result of calls to TerminateThread as they are used in a rather big library and I would prefer not modifying that.
To the com part of my question, with !htrace -diff i find thread handles allocated by msxml but not freed after the functioncalls end, could they be related to the leak or will they be Closed at a later time?
Thanks for all those comments, while the problem is still there they helped me understand it better.