[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Memory problems in OO context



|Ooops, after rereading the related pod, it seems I finally found a hint in
|Gisle Aas' HTML::Element:
|>BUGS
|>If you want to free the memory assosiated with a tree built of
|>HTML::Element nodes then you will have to delete it explicitly.  The
|>reason for this is that perl currently has no proper garbage collector,
|>but depends on reference counts in the objects.  This scheme fails because
|>the parse tree contains circular references (parents have references to
|>their children and children have a reference to their parent).
|There still remains a practical problem: What does this mean in relation to
|HTML::FormatText?
|Regarding the following snippet...
|
|foreach $file (@ARGV){
|	if (-f $file && $file !~/index\.htm./) {
|
|		open (OUT, ">>$outfile") or die $^E;
|		print OUT basename($file);
|
|		$html = parse_htmlfile($file);
|		$formatter = HTML::FormatText->new(leftmargin => 0,
|rightmargin =>
|100000);
|		$text = $formatter->format($html);
|		undef $html;
|		undef $formatter;
|
|		#further GREP-wise cleaning-up snipped
|
|		print OUT $text, "÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷÷\n\n";
|		undef $text;
|		close OUT;
|	}
|}
|...I don't see how I could possibly free up more memory. Am I doing
|something wrong here?

Yes. As Gisle's note says, you have to *explicitly* delete the html parse
tree. Just undefing it doesn't do it, that's *implicitly* deleting it,
which doesn't work because of circular references. Replace the undef $html
with $html->delete and see if that changes the behavior at all. (And yes, I
think that could be stated more clearly in the HTML pods.)

I've got a script that uses the HTML stuff to parse an HTML file and pull
some info out of it. I use delete and it seems to work fine, although it
only loops a few times so I may just not have run into the problem. It's an
easy change to try though.

Brian



# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org