<?xml version="1.0" encoding="windows-1252"?>
<node id="1001245" title="Re: Memory Leak Package" created="2012-10-28 00:21:34" updated="2012-10-28 00:21:34">
<type id="11">
note</type>
<author id="171588">
BrowserUk</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;&lt;/i&gt;&lt;/blockquote&gt;
&lt;p&gt;Reading between the lines of your last couple of OPs, you seem to be parsing multiple XML files with XML::Simple; and doing so in threads in the hope of preventing leaks?

&lt;p&gt;From a couple of quick experiments, it seems that whichever underlying parser -- XML::SAX, XML::SAX::PurePerl, XML::Parser -- you use, they all leak substantial amounts of memory. XML::SAX more so that XML::Parser, but still in the range of 10 to 30MB per iteration for a 12MB xml file.

&lt;p&gt;My suggestion to cure that -- essentially what [Zentara] suggested earlier, but with a twist -- is to run the parser in a separate process. I used this to parse the file and then export the structure back to the parent:&lt;code&gt;
#! perl -slw
use strict;
use Storable qw[ freeze ];
use XML::Simple; $XML::Simple::PREFERRED_PARSER = 'XML::Parser'; 

binmode STDOUT;
print freeze XMLin( $ARGV[ 0 ] );

&lt;/code&gt;

&lt;p&gt;And then in the main script just a simple backticks command and [thaw]:&lt;code&gt;
for( 1 .. 1000 ) {
    my $xml = thaw `xmlSto.pl junk.xml`;
    print mem $_; &lt;STDIN&gt;;
}
&lt;/code&gt;

&lt;p&gt;It took about 1 extra second or so for the parent process to get access to the data structure, but it cures the leak completely.

&lt;div class="pmsig"&gt;&lt;div class="pmsig-171588"&gt;
&lt;hr /&gt;
&lt;font size=1 &gt;
&lt;div&gt;With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'&lt;/div&gt;
&lt;div&gt;Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.&lt;/div&gt;
&lt;div&gt;"Science is about questioning the status quo. Questioning authority". &lt;/div&gt;
&lt;div&gt;In the absence of evidence, opinion is indistinguishable from prejudice.
&lt;p align=right&gt; [http://thebottomline.cpaaustralia.com.au/|RIP Neil Armstrong]&lt;/p&gt;&lt;/div&gt;
&lt;/font&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1001200</field>
<field name="parent_node">
1001200</field>
</data>
</node>
