Hi,
I've got a loop that goes through a directory of huge xml files and after some period of time, will eventually die with an out of memory error. While my program is running, the memory usage on the stat for it continues to go up until I get an out of memory error. It runs until it runs out of memory. I restart the application, and it starts running and parses the file it just died on previously.
perl(8145) malloc: *** vm_allocate(size=8421376) failed (error code=3) perl(8145) malloc: *** error: can't allocate region perl(8145) malloc: *** set a breakpoint in szone_error to debug Out of memory!
I'm guessing that its my usage of XML Dom. For each xml file in a directory, I create a new parser and a new doc. But I haven't found any code that will let me delete or free the parser or the doc the parser is parsed into. Could that be the problem? If so, how do I free it, and which should I free?
use XML::DOM; my @files = <$datapath/*.*>; foreach my $file (@files) { my $parser = XML::DOM::Parser->new(); my $doc = $parser->parsefile($file); ##I parse the documents }
ANSWER: Looks like its $doc->dispose.

In reply to XML Out of Memory by ecuguru

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.