Hello,

I have a xml file i want to parse. This part works so far. 
But my problem is that my xml file has a size of 20 MiB and more. So, if i work 
with such a file, then i can see that the allocated memory is not given back to 
the system after i call the mentioned free operations xmlFreeDoc(doc) and 
xmlFreeParserCtxt(). As far as i just create the doc tree and call the free 
operations i could "repair" the memory usage by calling malloc and free the 
allocated memory, but as soon as i touch the node contents in any way (see 
for-loop) i can't get the memory given back to the system!

And here is my code sample:

    xmlParserCtxtPtr ctxt; /* the parser context */
    xmlDocPtr doc; /* the resulting document tree */

    /* create a parser context */
    ctxt = xmlNewParserCtxt();
    if (ctxt == NULL) {
        fprintf(stderr, "Failed to allocate parser contextn");
return -12;
    }
    /* parse the file, activating the DTD validation option */
    doc = xmlCtxtReadFile(ctxt, nodeCoordinateSource, NULL, 0);

    /* check if parsing suceeded */
    if (doc == NULL) {
        fprintf(stderr, "Failed to parse %sn", nodeCoordinateSource);
    } else {
// /* check if validation suceeded */
//        if (ctxt->valid == 0)
//      fprintf(stderr, "Failed to validate %sn", nodeCoordinateSource);

        xmlNode *root = xmlDocGetRootElement(doc);

        /* get NodeRecords */
        if(root->type == XML_ELEMENT_NODE) {
         int found;
         xmlAttr *attr;
         const xmlChar *match = (const xmlChar *)"dimensions";

         for(attr = root->properties, found = 0; attr && !found; attr = 
(xmlAttr *)attr->next) {
if(!xmlStrcmp(attr->name, match)) {
dimensions = atoi((const char *)attr->children->content);
found = 1;
}
}
         attr = NULL;
         root = NULL;
        }

        /* free up the resulting document */
        xmlFreeDoc(doc);
        xmlFreeParserCtxt(ctxt);

        /* repair memory usage */
        ptr = (void *)malloc(1024*1024);
        free(ptr);
    }

Has anyone an idea how i can fix this?

Regards
Viktor



_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
http://mail.gnome.org/mailman/listinfo/xml

Reply via email to