WWW::Mechanize keeps a history of all visited pages, so your solution will work.
In reply to Re^2: memory consumption by Corion in thread memory consumption by moked