Re: Memory Leaks?

Marc Langheinrich (marclang@cs.washington.edu)
Mon, 7 Jul 1997 10:45:44 -0700 (PDT)


> But, unfortunately for me, I have some sort of leak somewhere.  (Nice and
> vauge)  In the standard code, for stripping HTML from a rawdata get, it goes
> like:
> 
>  	#Format the page as text
>     $htmldata = HTML::Parse::parse_html($rawdata);
>     $formatter = new HTML::FormatText;
>     $textdata = $formatter->format($htmldata);
> 
> (Which I have embedded in a loop that runs lots and lots 'o times.)
HTML::Parse (and friends) use circular data structures (i.e. $a points to 
$b, which in turn points back to $a), which cannot be free'd by Perl's 
garbage collection. Try this:

>     $htmldata = HTML::Parse::parse_html($rawdata);  
>     $formatter = new HTML::FormatText;  
>     $textdata = $formatter->format($htmldata); 

      # when we're done, free memory
      $htmldata->delete;  # explicitly free allocated memory, since Perl 
                          # can't

This should help...

Marc
---
Marc Langheinrich                  Department of Computer Science & Engr.
office phone: (206) 543-5129       University of Washington, Box 352350, 
email: marclang@cs.washington.edu  Seattle, WA 98195-2350, USA
www: http://www.cs.washington.edu/homes/marclang/