Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: how much memory each Perl variable uses

by BrowserUk (Pope)
on Sep 08, 2009 at 20:24 UTC ( #794216=note: print w/ replies, xml ) Need Help??


in reply to how much memory each Perl variable uses

I can start sprinkling Devel::Size::size() calls around the code, but that would be rather annoying,

If you run Devel::Size against %:: in the outermost loop of your program and then compare the output from one run to the next, it can help you isolate where the memory growth is occuring, you can then look more closely at the relevant area(s). (BTW: You'll need v0.72; 0.71 will blow up in mysterious way if you try this.)

use Devel::Size qw[ total_size];; printf "%30s: %d\n", $_, total_size( $::{ $_ } ) for keys %::;; _<C:/Perl64/site/lib/auto/Cwd/Cwd.dll: 499 version::: 13009 /: 490 stderr: 303 SIG: 5964 ,: 509 Tie::: 7454 utf8::: 5741 ": 405 constant::: 28942 re::: 44435 DynaLoader::: 63651 mro::: 5947 Devel::: 32202 Cwd::: 126954 strict::: 9683 stdout: 303 &#8597;: 274 |: 500 Regexp::: 1266 Term::: 1096 _code: 493 UNIVERSAL::: 3012 overload::: 59362 $: 293 time: 994 File::: 82769 &#8597;E_TRIE_MAXBUF: 323 Dos::: 831 size: 964 Data::: 168049 _<..\universal.c: 403 &#8597;E_DEBUG_FLAGS: 319 _<HiRes.c: 381 BEGIN: 253 _<..\mro.c: 391 !: 517 IO::: 1101 &#9788;: 517 total_size: 988 &#8593;: 370 pp: 19157 _: 497 ActivePerl::: 137287 _<C:/Perl64/lib/constant.pm: 463 Exporter::: 120414 Internals::: 4478 STDIN: 253 Config::: 113324 warnings::: 93953 DB::: 1071 Time::: 47484 EPOC::: 833 _<.\win32.c: 393 &#9644;: 936 _<perllib.c: 393 2: 524 _<Cwd.c: 375 cmpthese: 37036 1: 533 &#8616;ARNING_BITS: 553 CORE::: 1086 _<Size.c: 379 Win32CORE::: 1174 attributes::: 1176 stdin: 301 ARGV: 499 INC: 5306 _<..\activeperl.c: 405 _<C:/Perl64/site/lib/auto/Devel/Size/Size.dll: 533 Scalar::: 2018 ENV: 10062 ?: 493 vars::: 15120 subs::: 5644 _<..\perlio.c: 397 _<Win32CORE.c: 397 XSLoader::: 27593 main::: 1006356 AutoLoader::: 40075 VMS::: 2363 Carp::: 44867 Win32::: 17184 PerlIO::: 3024 0: 541 : 850 _<..\xsutils.c: 399 @: 1074 Benchmark::: 200847 n: 282 STDOUT: 255 3: 504 ]: 393 _<C:/Perl64/lib/auto/Time/HiRes/HiRes.dll: 509 &#8616;: 499 MIME::: 1412 STDERR: 255 ActiveState::: 72715 _<dl_win32.c: 401 sleep: 998

It won't always find the leak, but it can point you in the right direction.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: how much memory each Perl variable uses
Select or Download Code
Re^2: how much memory each Perl variable uses
by amir_e_a (Hermit) on Sep 09, 2009 at 10:42 UTC

    Thanks a lot! This looks like the right direction, but for some reason on my machine it immediately crashes:

    7 [main] perl 4156 _cygtls::handle_exceptions: Error while dumping sta +te (probably corrupted stack) Segmentation fault (core dumped)
    Maybe Devel::Size can't work on Cygwin? (Strange, but possible...)
      Maybe Devel::Size can't work on Cygwin? (Strange, but possible...)

      It only inspects Perl's internal structures, so should run anywhere Perl does, but since I don't use Cygwin, I neither know nor care.

      Why not run your script native for the purposes of solving your problem? Either on a native *nix platform if that's your target and your reason for using Cygwin (though developing under an emulator is a silly idea). Or native Win32 if that your target. (If so, why use the emulator?)


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        The target is not supposed to be important.

        I'd love to run it on Linux in principle, and it would be faster, too, but i don't have a Linux machine anywhere around.

        I use Cygwin Perl, because on Windows it's the friendliest environment for installing CPAN packages. Strawberry Perl tries to be friendly, but from my experience it isn't mature enough. ActivePerl is not CPAN-friendly at all.

Re^2: how much memory each Perl variable uses
by amir_e_a (Hermit) on Sep 09, 2009 at 10:45 UTC

    ...And besides, doesn't this approach miss out on "my" variables? Most of the variables there are defined as "my".

    Correct me if i'm wrong.

      Yes, but if you combine it with Devel::DumpSizes it can help you track down problems.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://794216]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-10-26 03:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (151 votes), past polls