0

I test the following code

#include <boost/property_tree/xml_parser.hpp>

namespace pt = boost::property_tree;

int main()
{
  { //1
    pt::ptree xml;
    pt::read_xml("very_big_xml.xml", xml);
    // xml.clear(); //destructor should do the job
  }
  { //2
    pt::ptree xml;
    pt::read_xml("very_big_xml.xml", xml);
  }
}

After first part, my application ocuppies huge memory amount (~6GB) and it crashes on second part because of lack of memory. Should I manually release property tree? Documentation says the destructor should clean up.

NOTE: uncommenting xml.clear(); doesn't help.

Mariusz Jaskółka
  • 4,137
  • 2
  • 21
  • 47

2 Answers2

0

Problem is that you are trying use DOM for very large xml.

DOM is vary handy and easy to understand, but it fails for large xml-s.

Proper way to solve this problem is to use SAX which is event driven. Using this approach you can process large xml even in 32 bit application without consuming large chunks of memory.

Now boost property tree is clearly DOM style and it fails not because ptree is broken, but this is shortcoming of DOM approach.

Most probably you built your application for 32 bit platform, which makes application to have 3GB memory limit.

Marek R
  • 32,568
  • 6
  • 55
  • 140
0

Works fine for me, boost::property_tree destructor is releasing memory as expected (Boost 1.73).

boost::property_tree memory usage

Try running under gdb and getting a backtrace (bt) when the app crashes.

Also try running under valgrind with a smaller file to see if it reports any leaks.

rustyx
  • 80,671
  • 25
  • 200
  • 267