Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How to prevent IXMLDOMDoc handle leak in multithread?

From: "Anthony Jones" <Ant@------------.--->
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.




transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent