Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: How to prevent IXMLDOMDoc handle leak in multithread?

From: "Anil Saraswathy"<anilgs@-----.--->
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


transparent
Print
Mail
Digg
delicious
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