I've done a fair bit of research on Xerces-C and how it manages memory, and
I understand that it uses reference counting to determine when it needs to
free up objects. I'm having a bit of a problem, however...
In C++, I'm using a DOMParser to read in an XHTML file, do a
DOMParser::getDocument() to get the DOM_Document, and use various DOM
methods to manipulate the XHTML file to insert dynamic content. This works
quite well and is a very flexible method of generating page content, but
this is where the memory problem kicks in.
I've got an XHTML table I'm trying to populate with data by using an XHTML
similar to this:
<tr id="template">
<td id="cell1" />
<td id="cell2" />
<td id="cell3" />
</tr>
with the idea that I can use a DOM_Document::getElementById() call to get
the tr and td elements, append a new text node to each td element to create
the content, get the parent node of the tr element, and
DOM_Node::cloneNode(true) on the tr element to add a new row onto the table.
When I use the cloneNode() method, the DOM_Node returned doesn't ever seem
to get released. The program is being run through FastCGI as a "persistent
CGI", and by watching process memory allocation (unfortunately I don't have
any licenses for good memory tracers like Purify) I can see memory usage
increase with every run through where the table is manipulated. I'm careful
to delete the DOMParser object between runs, and if I am just displaying a
static XHTML page (no DOM manipulation), the program does not leak memory.
I'm fairly confident I've isolated the memory leak to the cloneNode method.
Code snippet begins here:
DOM_Element row = thePage.getElementById("template");
DOM_Node table = user_row.getParentNode();
for(int i = 0; i < len; i++) {
setTextById("cell1", cell1_data);
// basically does an
DOM_Node::appendChild(DOM_Document::createTextNode(cell1_data))
setTextById("cell2", cell2_data);
setTextById("cell3", cell3_data);
DOM_Node clone = row.cloneNode(true);
table.appendChild(clone);
}
table.removeChild(row);
This code works and will generate the table, but it also leaks memory. If I
comment out the cloneNode call, memory stops leaking. If I comment out
everything except the cloneNode call, memory leaks. I haven't started
digging through the Xerces-C source code - I'm hoping to avoid that if at
all possible ;)
Help?!
o _ _ _
_o /\_ _ |\o (_)\__/o (_)
_< \_ _>(_) (_)/<_ \_| \ _|/' \/
(_)>(_)o (_) o o (_) o (_) (_)' _\o_
---------------------------------------------
Evan Day
SUMMIT Information Systems
[EMAIL PROTECTED]
(800) 937-7500 x6301
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]