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 Laurent Oget <de...@oget.net> on 2006/04/01 15:29:20 UTC

Re: re-posting: re-use of DOMDocument causing memory bloat?

>  
>
>>-----Original Message-----
>>From: Dor-Shifer Amit 
>>Sent: Sunday, March 26, 2006 10:36
>>To: 'c-users@xerces.apache.org'
>>Subject: re-use of DOMDocument causing memory bloat?
>>
>>Hello all,
>> 
>>In an application using xerces-c, I'm periodically printing 
>>an xml file, containing key=val data. val reflects app. data, 
>>and is constantly changing (statistic data).
>>
>>Frequently, val is set to '0'. In those cases, I consider it 
>>irrelevant for printing, so I wish to remove it from the 
>>final xml file. 
>>
>>The first solution for this was simply to recreate the DOM 
>>tree whenever time comes for printing. This impsed a heavy 
>>load (in terms of performance), so an alternative was 
>>thought-of, to re-use as much of the tree as possible. Each 
>>time we want to print it, we remove the redundant '0' data 
>>nodes, re-add the prev. removed nodes, and print. This 
>>implementation yields a gradually-increasing memory 
>>consumption. I traced it mainly to:
>>
>>1. DOMElementImpl::getElementsByTagName (used to locate the 
>>correct place to insert a node) 2. DOMElementImpl::release 
>>(used when the node is removed, because the val it contains ='0')
>>
>>So my questions are:
>>a. Is this concept of partial re-use of an XML tree wrong? If 
>>it's ok, then I'd expect the API not to hog memory.
>>b. Am I using the correct API for the task? If so, is there a 
>>way to impose a clean-up of memory?
>>c. If the concept of re-use here is indeed wrong, what would 
>>you advise as a solution for this issue, given that 
>>performance is important?
>>
>>10x,
>>Amit
>>
>>
>>
>>    
>>

It sounds like the DOM Tree somehow keeps traces of all nodes it ever held.
An ugly solution that does not involve digging into the guts of Xerces 
would be
to recreate the tree once for every thousandth print.

good luck,

laurent