Re: [xml] Memory leak / cleanup missing after node creation.




Thanks again Igor! During the process I also found some more memory oddness - the following below doesn't register as a leak using 'leaks' in FreeBSD Terminal, but I see the memory go up:

        In my (multithreaded) app I have x amount of buffers allocated with:

        theFinalXML = xmlBufferCreateSize(8192);

If, for example, I perform a 'xmlBufferLength(theFinalXML)' I get back zero. Er, OK, weird, since I thought 'xmlBufferCreateSize' can pre-allocate a known size so the buffer doesn't need to be constantly re-malloc'ed (or whatever scheme it uses).

        So if I dump the buffer (this is in my main thread loop):

        theFinalXMLSize = xmlNodeDump(theFinalXML, doc, root_element, 0, 0);

        I *have* to perform:

        xmlBufferEmpty(theFinalXML);

afterwards, otherwise the buffers grow and grow. Um, I am fine with using BufferEmpty (apart from the performace hit of constant allocs and reallocs), but then what use has 'xmlBufferCreateSize' ?


Regards,
                Jose.

On 24 May 2004, at 5:30 pm, Igor Zlatkovic wrote:

On 24/05/04 17:59, Jose Commins wrote:
    By the way,
                    newNode = xmlNewText(theTagReplacements[1]);
                    xmlReplaceNode(cur_node, newNode);
It still looks like a list of 'newNode's still has to be created and freed with 'xmlFreeNode' after 'xmlFreeDoc' is called; despite being assigned to the doc, xmlFreeDoc doesn't seem to remove the allocations for those 'newNode' s.

That's probably because a new text node should be created in the context of the document. Try

  newNode = xmlNewDocText(cur_node->doc, theTagReplacements[1]);

That should pepper it to fit most tastes.

Ciao,
Igor





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]