http://www.perlmonks.org?node_id=498401


in reply to Total Memory Size Used up by a Perl Script

Try using Devel::Size::total_size on %::;

perl> use Devel::Size qw[ total_size size ];; perl> print total_size( \%:: );; [warnings omitted] 264621 perl> @a = 'A'..'M';; perl> print total_size( \@a );; 446 perl> print total_size( \%:: );; [warnings omitted] 265437 perl> @b{ 1 .. 100000 } = 1..100000;; perl> print total_size( \%b );; 4813243 perl> print total_size( \%:: );; [warnings omitted] 6803729

As you can see, the numbers don't exactly add up, but the do give you a pretty good ballpark figure.

Now, if only I can work out how to supress that dratted warning.

Update: I found it: $Devel::Size::warn=0;. With that, you can get a rough idea of where the memory your script uses is being used:

perl> use Devel::Size qw[ total_size ];; perl> $Devel::Size::warn = 0;; perl> print $_, ':', total_size( \$::{$_} ) for keys %::;; / : 382 stderr : 289 SIG : 3705 , : 399 utf8:: : 4359 " : 307 _<c:/Perl/site/lib/auto/Devel/Size/Size.dll : 479 DynaLoader:: : 15131 Devel:: : 7292 strict:: : 2185 stdout : 289 ↕ : 262 | : 378 _<c:/Perl/lib/auto/Time/HiRes/HiRes.dll : 463 Mac:: : 1701 Regexp:: : 948 _<c:/Perl/lib/auto/Data/Dumper/Dumper.dll : 469 UNIVERSAL:: : 1872 overload:: : 10646 $ : 287 Data:: : 22260 - : 679 _<..\universal.c : 363 _<HiRes.c : 343 BEGIN : 287 ! : 402 IO:: : 943 ☼ : 394 total_size : 487 ↑ : 345 _ : 414 + : 679 Exporter:: : 16111 Internals:: : 3384 STDIN : 287 Config:: : 54023 warnings:: : 19489 DB:: : 850 Time:: : 10381 _<.\win32.c : 343 ▬ : 345 _<perllib.c : 343 cmpthese : 489 1 : 402 ↨ARNING_BITS : 400 CORE:: : 930 _<Size.c : 339 attributes:: : 962 stdin : 287 ARGV : 405 INC : 2499 timethis : 489 ENV : 6657 Scalar:: : 1810 ? : 395 vars:: : 1545 _<..\perlio.c : 351 XSLoader:: : 1247 B:: : 951 main:: : 264297 AutoLoader:: : 2800 VMS:: : 1224 Carp:: : 11075 Win32:: : 11257 PerlIO:: : 2370 0 : 431 : 562 _<..\xsutils.c : 355 @ : 950 Benchmark:: : 25689 STDOUT : 289 ] : 355 ↨ : 407 Dumper : 479 STDERR : 289 bytes:: : 2985 _<Dumper.c : 345 _<dl_win32.c : 330 <none>:: : 460

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.