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: 7/5/2007 9:33:00 AM
"Bethany" <BB@-.-> wrote in message
news:eLI2RzbvHHA.4012@T......
> 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.
>
>
How are you measuring handles? Have you tried to establish what the handles
refer to?
Try searching for XML memory leak in this group you might find this issue is
related to how XML garbage collects some of the resources it uses.
| ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
