You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by al...@email.ru on 2004/09/21 10:01:43 UTC

Memory leaks while releasing DOMNode...

Hello xerces-c-dev,


Xerces-C   version number - 2.5.0
Platform - Intel Pentium 4
Operating system and version number - Microsoft Windows 
2000 AS
Compiler and version number - cygwin (Visual C   7.0)
The C   application code that failed:
//--------------------------------------------------------
---------------------------
#include <stdio.h>
#include <conio.h>
#include <xercesc/dom/DOM.hpp>

XERCES_CPP_NAMESPACE_USE

int main(int argc, char* argv [])
{
        XMLPlatformUtils::Initialize();

        XMLCh * xml_str;

        DOMImplementation* impl = 
DOMImplementationRegistry::getDOMImplementation(0);

        xml_str = XMLString::transcode( "root" );
        DOMDocument*   doc = impl->createDocument(0, 
xml_str, 0);
        XMLString::release( &xml_str );
        DOMElement*   root = doc->getDocumentElement();

        xml_str = XMLString::transcode( "FirstElement" );
        DOMElement*   e1 = doc->createElement(xml_str);
        XMLString::release( &xml_str );
        root->appendChild(e1);

        xml_str = XMLString::transcode( "SecondElement" );
        DOMElement*   e2 = doc->createElement(xml_str);
        XMLString::release( &xml_str );
        root->appendChild(e2);

        xml_str = XMLString::transcode( "aTextNode" );
        DOMText*       textNode = doc->createTextNode
(xml_str);
        XMLString::release( &xml_str );
        e1->appendChild(textNode);

        printf("Step 1\n");                     // Memory 
usage 2 MB
        getch();

        for( int i=0; i<5000000; i   )
        {
              DOMNode * node = e1->cloneNode(true);
              node->release();
        }

        printf("Step 2\n");                     // Memory 
usage 158 MB !!!
        getch();

        doc->release();

        printf("Step 3\n");                     // Memory 
usage 7 MB
        getch();

        XMLPlatformUtils::Terminate();

        return 0;
}
//--------------------------------------------------------
---------------------------

What happened - memory usage:
  step 1 - 2 MB,
  step 2 - 158 MB (!!!),
  step 3 - 7 MB.


-- 
Best regards,
   alexch                          mailto:alexch@email.ru

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Memory leaks while releasing DOMNode...

Posted by Gareth Reakes <ga...@parthenoncomputing.com>.
Hi,
	this is expected. Not all the memory associated with the element is 
released (for example the attribute list in elements).

Gareth

On 21 Sep 2004, at 9:01, alexch@email.ru wrote:

> Hello xerces-c-dev,
>
>
> Xerces-C   version number - 2.5.0
> Platform - Intel Pentium 4
> Operating system and version number - Microsoft Windows
> 2000 AS
> Compiler and version number - cygwin (Visual C   7.0)
> The C   application code that failed:
> //--------------------------------------------------------
> ---------------------------
> #include <stdio.h>
> #include <conio.h>
> #include <xercesc/dom/DOM.hpp>
>
> XERCES_CPP_NAMESPACE_USE
>
> int main(int argc, char* argv [])
> {
>         XMLPlatformUtils::Initialize();
>
>         XMLCh * xml_str;
>
>         DOMImplementation* impl =
> DOMImplementationRegistry::getDOMImplementation(0);
>
>         xml_str = XMLString::transcode( "root" );
>         DOMDocument*   doc = impl->createDocument(0,
> xml_str, 0);
>         XMLString::release( &xml_str );
>         DOMElement*   root = doc->getDocumentElement();
>
>         xml_str = XMLString::transcode( "FirstElement" );
>         DOMElement*   e1 = doc->createElement(xml_str);
>         XMLString::release( &xml_str );
>         root->appendChild(e1);
>
>         xml_str = XMLString::transcode( "SecondElement" );
>         DOMElement*   e2 = doc->createElement(xml_str);
>         XMLString::release( &xml_str );
>         root->appendChild(e2);
>
>         xml_str = XMLString::transcode( "aTextNode" );
>         DOMText*       textNode = doc->createTextNode
> (xml_str);
>         XMLString::release( &xml_str );
>         e1->appendChild(textNode);
>
>         printf("Step 1\n");                     // Memory
> usage 2 MB
>         getch();
>
>         for( int i=0; i<5000000; i   )
>         {
>               DOMNode * node = e1->cloneNode(true);
>               node->release();
>         }
>
>         printf("Step 2\n");                     // Memory
> usage 158 MB !!!
>         getch();
>
>         doc->release();
>
>         printf("Step 3\n");                     // Memory
> usage 7 MB
>         getch();
>
>         XMLPlatformUtils::Terminate();
>
>         return 0;
> }
> //--------------------------------------------------------
> ---------------------------
>
> What happened - memory usage:
>   step 1 - 2 MB,
>   step 2 - 158 MB (!!!),
>   step 3 - 7 MB.
>
>
> -- 
> Best regards,
>    alexch                          mailto:alexch@email.ru
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>
>
>
--
Gareth Reakes, Managing Director      Parthenon Computing
+44-1865-811184                  http://www.parthcomp.com


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Memory leaks while releasing DOMNode...

Posted by Gareth Reakes <ga...@parthenoncomputing.com>.
Hi,
	The only way to free all the memory is to delete the document. In 
extreme circumstances, you can clone the whole doc and then release the 
old one.

Gareth

alexch@email.ru wrote:

> Hello Gareth,
> 
> What should I do if I use DOMNode::cloneNode() function 
> very frequently?
> 
> Best regards,
>    alexch                 mailto:alexch@email.ru
> 
> 
>>Hi,
>>this is expected. Not all the memory associated with the 
> 
> element is 
> 
>>released (for example the attribute list in elements).
>>
>>Gareth
> 
> 
>>>Xerces-C   version number - 2.5.0
>>>Platform - Intel Pentium 4
>>>Operating system and version number - Microsoft Windows
>>>2000 AS
>>>Compiler and version number - cygwin (Visual C   7.0)
>>>The C   application code that failed:
>>>//-----------------------------------------------------
> 
> ---
> 
>>>---------------------------
>>>#include <stdio.h>
>>>#include <conio.h>
>>>#include <xercesc/dom/DOM.hpp>
>>>
>>>XERCES_CPP_NAMESPACE_USE
>>>
>>>int main(int argc, char* argv [])
>>>{
>>>        XMLPlatformUtils::Initialize();
>>>
>>>        XMLCh * xml_str;
>>>
>>>        DOMImplementation* impl =
>>>DOMImplementationRegistry::getDOMImplementation(0);
>>>
>>>        xml_str = XMLString::transcode( "root" );
>>>        DOMDocument*   doc = impl->createDocument(0,
>>>xml_str, 0);
>>>        XMLString::release( &xml_str );
>>>        DOMElement*   root = doc->getDocumentElement();
>>>
>>>        xml_str = XMLString::transcode
> 
> ( "FirstElement" );
> 
>>>        DOMElement*   e1 = doc->createElement(xml_str);
>>>        XMLString::release( &xml_str );
>>>        root->appendChild(e1);
>>>
>>>        xml_str = XMLString::transcode
> 
> ( "SecondElement" );
> 
>>>        DOMElement*   e2 = doc->createElement(xml_str);
>>>        XMLString::release( &xml_str );
>>>        root->appendChild(e2);
>>>
>>>        xml_str = XMLString::transcode( "aTextNode" );
>>>        DOMText*       textNode = doc->createTextNode
>>>(xml_str);
>>>        XMLString::release( &xml_str );
>>>        e1->appendChild(textNode);
>>>
>>>        printf("Step 1\n");                     // 
> 
> Memory
> 
>>>usage 2 MB
>>>        getch();
>>>
>>>        for( int i=0; i<5000000; i   )
>>>        {
>>>              DOMNode * node = e1->cloneNode(true);
>>>              node->release();
>>>        }
>>>
>>>        printf("Step 2\n");                     // 
> 
> Memory
> 
>>>usage 158 MB !!!
>>>        getch();
>>>
>>>        doc->release();
>>>
>>>        printf("Step 3\n");                     // 
> 
> Memory
> 
>>>usage 7 MB
>>>        getch();
>>>
>>>        XMLPlatformUtils::Terminate();
>>>
>>>        return 0;
>>>}
>>>//-----------------------------------------------------
> 
> ---
> 
>>>---------------------------
>>>
>>>What happened - memory usage:
>>>  step 1 - 2 MB,
>>>  step 2 - 158 MB (!!!),
>>>  step 3 - 7 MB.
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
> 
> 

-- 
Gareth Reakes, Managing Director      Parthenon Computing
+44-1865-811184                  http://www.parthcomp.com

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Memory leaks while releasing DOMNode...

Posted by al...@email.ru.
Hello Gareth,

What should I do if I use DOMNode::cloneNode() function 
very frequently?

Best regards,
   alexch                 mailto:alexch@email.ru

>Hi,
>this is expected. Not all the memory associated with the 
element is 
>released (for example the attribute list in elements).
>
>Gareth

>> Xerces-C   version number - 2.5.0
>> Platform - Intel Pentium 4
>> Operating system and version number - Microsoft Windows
>> 2000 AS
>> Compiler and version number - cygwin (Visual C   7.0)
>> The C   application code that failed:
>> //-----------------------------------------------------
---
>> ---------------------------
>> #include <stdio.h>
>> #include <conio.h>
>> #include <xercesc/dom/DOM.hpp>
>>
>> XERCES_CPP_NAMESPACE_USE
>>
>> int main(int argc, char* argv [])
>> {
>>         XMLPlatformUtils::Initialize();
>>
>>         XMLCh * xml_str;
>>
>>         DOMImplementation* impl =
>> DOMImplementationRegistry::getDOMImplementation(0);
>>
>>         xml_str = XMLString::transcode( "root" );
>>         DOMDocument*   doc = impl->createDocument(0,
>> xml_str, 0);
>>         XMLString::release( &xml_str );
>>         DOMElement*   root = doc->getDocumentElement();
>>
>>         xml_str = XMLString::transcode
( "FirstElement" );
>>         DOMElement*   e1 = doc->createElement(xml_str);
>>         XMLString::release( &xml_str );
>>         root->appendChild(e1);
>>
>>         xml_str = XMLString::transcode
( "SecondElement" );
>>         DOMElement*   e2 = doc->createElement(xml_str);
>>         XMLString::release( &xml_str );
>>         root->appendChild(e2);
>>
>>         xml_str = XMLString::transcode( "aTextNode" );
>>         DOMText*       textNode = doc->createTextNode
>> (xml_str);
>>         XMLString::release( &xml_str );
>>         e1->appendChild(textNode);
>>
>>         printf("Step 1\n");                     // 
Memory
>> usage 2 MB
>>         getch();
>>
>>         for( int i=0; i<5000000; i   )
>>         {
>>               DOMNode * node = e1->cloneNode(true);
>>               node->release();
>>         }
>>
>>         printf("Step 2\n");                     // 
Memory
>> usage 158 MB !!!
>>         getch();
>>
>>         doc->release();
>>
>>         printf("Step 3\n");                     // 
Memory
>> usage 7 MB
>>         getch();
>>
>>         XMLPlatformUtils::Terminate();
>>
>>         return 0;
>> }
>> //-----------------------------------------------------
---
>> ---------------------------
>>
>> What happened - memory usage:
>>   step 1 - 2 MB,
>>   step 2 - 158 MB (!!!),
>>   step 3 - 7 MB.


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org