I don't believe it is leaking memory? Here's a quote from the perldoc for WWW::Mechanize.

Mech also stores a history of the URLs you've visited, which can be queried and revisited.
Also, here's the output I get from your program.

agent size = 123086
agent size = 245249
agent size = 367383
agent size = 489517
agent size = 611651

This shows me that the size is going up by an almost constant size each loop. I then modified your program to use Data::Dumper and spit out the results after five GETs. Here's the code.

#!/usr/bin/perl -w + use strict; use WWW::Mechanize; use Devel::Size qw(size total_size); use Data::Dumper; + my $agent = WWW::Mechanize->new(); + for(my $i = 0; $i < 5; $i++) { $agent->get(qq(http://www.yahoo.com)); print "agent size = ".total_size($agent)."\n"; } + print Dumper($agent);

Looking at the output, there is a data structure that is part of the module called the page_stack. I'm guessing, that the implementation of the back() method uses the page_stack. That way, rather than re-requesting the pages, the pages are just reloaded from memory. I don't think this is a leak. This is just appears to be the functionality of the module.


In reply to Re: WWW::Mechanize memory leak??? by Steve_p
in thread WWW::Mechanize memory leak??? by cwchang

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.