[Israel.pm] how much memory each Perl variable uses

Offer Kaye offer.kaye at gmail.com
Thu Sep 10 05:24:44 PDT 2009

On Wed, Sep 9, 2009 at 1:46 PM, Amir E. Aharoni wrote:
> Is there any convenient tool which can produce a detailed list of all
> the memory usage of a Perl program during runtime?

The best advice I've seen about profiling memory usage is to use an
external tool called Valgrind[1] which is supposed to be very good for
such work. There's a perlmonks thread which might help you with some
env settings[2]. There's also a CPAN module called Test::Valgrind[3]
and if you look at the "SEE ALSO" section[4] in its pod you will see a
few other memory profiling options listed. Note the caveat, you'll
likely want to use a perl built with debugging enabled.

Apart from direct memory profiling, understanding where your code
spends the most time might also help. Hands down the best module for
that is Devel::NYTProf [5] - I would at least give it a try to see if
it brings up anything.

[1] http://valgrind.org/
[2] http://www.perlmonks.org/?node_id=550458
[3] http://search.cpan.org/dist/Test-Valgrind
[4] http://search.cpan.org/dist/Test-Valgrind/lib/Test/Valgrind.pm#SEE_ALSO
[5] http://search.cpan.org/dist/Devel-NYTProf/

Offer Kaye

More information about the Perl mailing list