Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jozef (8299)

jozef
  (email not shown publicly)
http://jozef.kutej.net/
Jabber: jozef@kutej.net

Journal of jozef (8299)

Tuesday June 22, 2010
12:22 PM

sub r {return if !$_[0]; r($_[0]-1); } leaktrace{ r(1);};

[ #40411 ]

Today @$work we discovered that even dummy recursive calling of a function is leaking memory. Here is the one-liner 10000x calling it self and returning:

perl -MEnglish -MGTop -le 'my $g=GTop->new();$m=$g->proc_mem($PID);print $m->size; sub r { return if not $_[0]; r($_[0]-1); } r(100000); $m=$g->proc_mem($PID); print $m->size;'

The output is:

7122944
34729984

Before the recursion 7MB allocated. After the recursion (that finished) 34MB...

Here is what Test::LeakTrace say about it:

$ perl -MTest::LeakTrace -le 'sub r { return if not $_[0]; r($_[0]-1); } leaktrace{ r(1); };'
leaked ARRAY(0x9b7e8e8) from -e line 1.
leaked SCALAR(0x9b98cb8) from -e line 1.
leaked ARRAY(0x9c311f8) from -e line 1.
leaked SCALAR(0x9c311e8) from -e line 1.

Are we doing anything wrong? Is it ok? How to release the memory?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • #p5p

    [16:49] <shadowpaste> "daxim" at 217.168.150.38 pasted "recursion does not release memory for reuse?" (14 lines) at http://paste.scsys.co.uk/45082
    [16:49] <dipsy> [ magnet_web paste from "daxim" at 217.168.150.38... ]
    [16:49] <daxim> what's going on here?
    [16:50] <Zefram> fragmentation?
    [16:50] <purl> fragmentation is interesting
    [16:50] <Nicholas> no, Pad frames created for recursion are not released
    [16:50] <Nicholas> the assumption is that you'll recurse again
    [16:

    • perl -MTest::LeakTrace -le 'sub r {return if !$_[0]; r($_[0]-1); } r(1); leaktrace{ r(1);};'

      Hmm yes the second recursion calling is not leaking memory any more.