You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Kosaraju Karuna-C9013Z <C9...@motorola.com> on 2007/01/29 22:43:23 UTC

MemoryLeaks in Xerces

Hi,
 
We have designed a tool to read the XML file using SAX Parser.
Our tool has two interface APIs, initialize() and terminate().
In the Initialize method, we do invoke
 
-XMLPlatformUtils::Initialize(); followed by, 
 
pParser=XMLReaderFactory::createXMLReader();
pParser->setFeature(XMLUni::fgSAX2CoreValidation, false);
pParser->setFeature(XMLUni::fgXercesDynamic, false);
pParser->setFeature(XMLUni::fgXercesSchema, false);
pParser->setFeature(XMLUni::fgXercesSchemaFullChecking,false);
pParser->setContentHandler(this);
pParser->setErrorHandler(this);
 
pParser->parse(pXmlFile);
 
And in the terminate API call, we do invoke
 
XMLPlatformUtils::terminate()
 
When we just invoke initialize and terminate, we do see some memory
leaks. The purify shows somethindg as below
 
PLK: 9856 bytes potentially leaked in 176 blocks
  * This memory was allocated from:
 malloc         [rtlib.o]
 operator new(unsigned) [libstdc++.so.5]
 operator new(unsigned) []
 xercesc_2_6::MemoryManagerImpl::allocate(unsigned)
[MemoryManagerImpl.cpp:46]
 xercesc_2_6::XMemory::operator new(unsigned,
xercesc_2_6::MemoryManager*) [XMemory.cpp:66]
 xercesc_2_6::IGXMLScanner::scanStartTagNS(bool&)
[IGXMLScanner.cpp:2367]
  * Block of 56 bytes (176 times); last block at 0x816dbe0
 
PLK: 9448 bytes potentially leaked in 2 blocks
  * This memory was allocated from:
 malloc         [rtlib.o]
 operator new(unsigned) [libstdc++.so.5]
 operator new(unsigned) []
 std::__default_alloc_template<true, 0 >::_S_chunk_alloc(unsigned, int&)
[libstdc++.so.5]
 std::__default_alloc_template<true, 0 >::_S_refill(unsigned)
[libstdc++.so.5]
 std::__default_alloc_template<true, 0 >::allocate(unsigned)
[libstdc++.so.5]
  * Block of 4776 bytes at 0x80c1300
  * Block of 4672 bytes at 0x80bf6b8
 
Where could be the possible leak? We are using xerces 2.6.Are we
supposed to invoke any other API apart from
XMLPlatformUtils::terminate()??
Pls let us know. Thanks in advance. 
 
Regards
Karuna

RE: MemoryLeaks in Xerces

Posted by Kosaraju Karuna-C9013Z <C9...@motorola.com>.
Hi Dave

I think introducing the below line in my code should free the XMLReader.
delete pParser 
Pls let me know, if there is any other way of doing this.

Thanks
Karuna

-----Original Message-----
From: David Bertoni [mailto:dbertoni@apache.org] 
Sent: Tuesday, January 30, 2007 2:22 PM
To: c-users@xerces.apache.org
Subject: Re: MemoryLeaks in Xerces

Kosaraju Karuna-C9013Z wrote:
> Hi,
>  
> We have designed a tool to read the XML file using SAX Parser.
> Our tool has two interface APIs, initialize() and terminate().
> In the Initialize method, we do invoke
>  
> -XMLPlatformUtils::Initialize(); followed by,
>  
> pParser=XMLReaderFactory::createXMLReader();

...

>  
> When we just invoke initialize and terminate, we do see some memory 
> leaks. The purify shows somethindg as below
>  
> PLK: 9856 bytes potentially leaked in 176 blocks
>   * This memory was allocated from:
>  malloc         [rtlib.o]
>  operator new(unsigned) [libstdc++.so.5]  operator new(unsigned) []
>  xercesc_2_6::MemoryManagerImpl::allocate(unsigned)
> [MemoryManagerImpl.cpp:46]
>  xercesc_2_6::XMemory::operator new(unsigned,
> xercesc_2_6::MemoryManager*) [XMemory.cpp:66]
>  xercesc_2_6::IGXMLScanner::scanStartTagNS(bool&)
> [IGXMLScanner.cpp:2367]
>   * Block of 56 bytes (176 times); last block at 0x816dbe0

Did you delete the XMLReader instance you created in the call to
XMLReaderFactory::createXMLReader()?

>  
> PLK: 9448 bytes potentially leaked in 2 blocks
>   * This memory was allocated from:
>  malloc         [rtlib.o]
>  operator new(unsigned) [libstdc++.so.5]  operator new(unsigned) []  
> std::__default_alloc_template<true, 0 >::_S_chunk_alloc(unsigned, 
> int&) [libstdc++.so.5]  std::__default_alloc_template<true, 0 
> >::_S_refill(unsigned) [libstdc++.so.5]  
> std::__default_alloc_template<true, 0 >::allocate(unsigned) 
> [libstdc++.so.5]
>   * Block of 4776 bytes at 0x80c1300
>   * Block of 4672 bytes at 0x80bf6b8

Xerces-C doesn't use any templates from the standard library, so this
may be a spurious report, or a leak in your code.

Dave

Re: MemoryLeaks in Xerces

Posted by David Bertoni <db...@apache.org>.
Kosaraju Karuna-C9013Z wrote:
> Hi,
>  
> We have designed a tool to read the XML file using SAX Parser.
> Our tool has two interface APIs, initialize() and terminate().
> In the Initialize method, we do invoke
>  
> -XMLPlatformUtils::Initialize(); followed by, 
>  
> pParser=XMLReaderFactory::createXMLReader();

...

>  
> When we just invoke initialize and terminate, we do see some memory
> leaks. The purify shows somethindg as below
>  
> PLK: 9856 bytes potentially leaked in 176 blocks
>   * This memory was allocated from:
>  malloc         [rtlib.o]
>  operator new(unsigned) [libstdc++.so.5]
>  operator new(unsigned) []
>  xercesc_2_6::MemoryManagerImpl::allocate(unsigned)
> [MemoryManagerImpl.cpp:46]
>  xercesc_2_6::XMemory::operator new(unsigned,
> xercesc_2_6::MemoryManager*) [XMemory.cpp:66]
>  xercesc_2_6::IGXMLScanner::scanStartTagNS(bool&)
> [IGXMLScanner.cpp:2367]
>   * Block of 56 bytes (176 times); last block at 0x816dbe0

Did you delete the XMLReader instance you created in the call to 
XMLReaderFactory::createXMLReader()?

>  
> PLK: 9448 bytes potentially leaked in 2 blocks
>   * This memory was allocated from:
>  malloc         [rtlib.o]
>  operator new(unsigned) [libstdc++.so.5]
>  operator new(unsigned) []
>  std::__default_alloc_template<true, 0 >::_S_chunk_alloc(unsigned, int&)
> [libstdc++.so.5]
>  std::__default_alloc_template<true, 0 >::_S_refill(unsigned)
> [libstdc++.so.5]
>  std::__default_alloc_template<true, 0 >::allocate(unsigned)
> [libstdc++.so.5]
>   * Block of 4776 bytes at 0x80c1300
>   * Block of 4672 bytes at 0x80bf6b8

Xerces-C doesn't use any templates from the standard library, so this may 
be a spurious report, or a leak in your code.

Dave

Re: MemoryLeaks in Xerces

Posted by Boris Kolpackov <bo...@codesynthesis.com>.
Hi,

"Kosaraju Karuna-C9013Z" <C9...@motorola.com> writes:


> -XMLPlatformUtils::Initialize(); followed by,
>
> pParser=3DXMLReaderFactory::createXMLReader();
> pParser->setFeature(XMLUni::fgSAX2CoreValidation, false);
> pParser->setFeature(XMLUni::fgXercesDynamic, false);
> pParser->setFeature(XMLUni::fgXercesSchema, false);
> pParser->setFeature(XMLUni::fgXercesSchemaFullChecking,false);
> pParser->setContentHandler(this);
> pParser->setErrorHandler(this);
>
> pParser->parse(pXmlFile);
>
> And in the terminate API call, we do invoke
>
> XMLPlatformUtils::terminate()
>
> When we just invoke initialize and terminate, we do see some memory
> leaks.

Perhaps you should also release the parser somewhere. E.g., add

delete pParser;

before

XMLPlatformUtils::terminate();


hth,
-boris


-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
Open-Source, Cross-Platform C++ XML Data Binding