![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - How to prevent IXMLDOMDoc handle leak in multithread? [Thread Next] RE: How to prevent IXMLDOMDoc handle leak in multithread?To: NULL Date: 8/9/2007 6:40:00 AM
> I'm using xml messages for various communications in my application.
>
> The application is multithreaded and some of the more complicated
> interactions have IXMLDOMDoc messages being handed from one thread to
> another and destroyed by the other thread when done (the messages are
> too large and numerous to be translating the whole DOM to string form
> and back again).
>
> I have a handle leak which I can demonstrate with the code below:
>
> ===============================================================
> ===============================================================
> #include "msxml2.h" // Linker includes msxml2.lib
>
> DWORD WINAPI TestThread(LPVOID blah)
> {
> CoInitialize(NULL); // +2 handles
>
> CComPtr <IXMLDOMDocument> xmlDomDoc2;
> xmlDomDoc2.CoCreateInstance(L"MSXML2.DOMDocument.3.0", NULL,
> CLSCTX_INPROC_SERVER); // +4 handles
> xmlDomDoc2.Release(); // -0 handles
>
> CoUninitialize(); // -0 handles
>
> return 0;
> }
>
>
> void SmartPointerXMLDOMDocTest()
> {
> // Start off with 44 handles
>
> CoInitialize(NULL); // +9 handles
>
> CComPtr <IXMLDOMDocument> xmlDomDoc1;
> xmlDomDoc1.CoCreateInstance(L"MSXML2.DOMDocument.3.0", NULL,
> CLSCTX_INPROC_SERVER); // +20 handles
> xmlDomDoc1.Release(); // -0 handles
>
> DWORD threadID = NULL;
> CreateThread(NULL, NULL, TestThread, NULL, 0, &threadID); // +1
> handle
>
> Sleep(5000); // Allow time for thread to complete (which it does).
>
> CoUninitialize(); // -25 handles
>
> // End with 55 handles
> }
>
> ===================================================================
> ===================================================================
>
>
> Every time a new thread creates an IXMLDOMDoc it allocates handles which
> are not cleaned up until every thread calls CoUninitialize.
>
> You can't call CoUninitialize until your not going to use the IXMLDOMDoc
> again.
>
> This means that if _any_ thread holds onto one of these docs, then
> _none_ of the other threads' handles are ever cleaned up.
>
> This would be fine, but some parts of the app use XML for storage, not
> just message passing, so they may never let go of their xml docs until
> the app is finished.
>
> At the rate my app passes messages, I can pick up about 50k handles in a
> few minutes.
>
>
> I've been at this for weeks, so flames are fine as long as something
> useful comes of it.
>
>
> -BB
I have the same problem.
I tried with MSXML2, 3, 4, 5 and 6 - but the problem still exists. It seems 4 semaphore handles are leaked everytime I CoCreate an MSXML DOM object and release it. There was an article which said that perhaps I should turn OFF the full garbage collection. I tried creating a NoFullGC registry DWORD value set to 1. No success. I am surprised that Microsoft has been keeping mum on the issue.
Way to go, Microsoft !!!
I am now forced to rearchitect my code in order to avoid creating too many DOM parser objects from a worker thread.
BizTalk Utilities - Frustration free BizTalk Adapters
http://www.topxml.com/biztalkutilities
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||
|
