Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Oddity with memory manglement in 5.8.8, 5.10.0

by lembark (Novice)
on Jan 30, 2008 at 15:34 UTC ( #665148=note: print w/replies, xml ) Need Help??


in reply to Oddity with memory manglement in 5.8.8, 5.10.0

I figured it was a known issue, thanks.
Annoyance is that that the thing doesn't have to be recursive, guess I have to use a skip list to destroy the thing in chunks.
The code for tesing this and finding the limit is trivial:
#!/opt/bin/perl use strict; select STDERR; $| = 1; print "\nCount, Last value:\n"; for my $count ( 2**15 .. 2**18) { print "Testing: $count -> "; my $head = []; my $node = $head; ( $node ) = @{ $node } = ( [], $_ ) for 1 .. $count; bless $node, 'TailNode'; my $value = ''; for( $node = $head ; @$node ; ) { ( $node, $value ) = @$node; } print "$value\n"; # $head goes out of scope and segfaults here. } package TailNode; DESTROY { print "Destroying $_[0]\n"; } __END__ Trial runs: Teseting: 37405 -> 37405 Destroying TailNode=ARRAY(0x82d7f40) Teseting: 37406 -> 37406 Destroying TailNode=ARRAY(0x83425b0) Teseting: 37407 -> 37407 Segmentation fault

Replies are listed 'Best First'.
Re^2: Oddity with memory manglement in 5.8.8, 5.10.0
by almut (Canon) on Jan 30, 2008 at 17:49 UTC
    ...the thing doesn't have to be recursive

    The issue is that while running your code, perl internally builds up a call stack of impressive depth (218255 frames here — my attempt segfaulted at $count being around 43650 (with the default ulimit -s setting of 8192kB)), as shown by the backtrace based on the core dump:

    $ ./665040.pl Count, Last value: Testing: 43650 -> 43650 Segmentation fault (core dumped) $ gdb /usr/local/perl/5.10.0/bin/perl core (...) Core was generated by `/usr/local/perl/5.10.0/bin/perl ./665040.pl'. Program terminated with signal 11, Segmentation fault. #0 0x080acd57 in Perl_sv_clear () (gdb) bt #0 0x080acd57 in Perl_sv_clear () #1 0x080ad378 in Perl_sv_free2 () #2 0x0809915f in Perl_av_undef () #3 0x080ad129 in Perl_sv_clear () #4 0x080ad378 in Perl_sv_free2 () #5 0x080acd5f in Perl_sv_clear () #6 0x080ad378 in Perl_sv_free2 () (...) (...) #218242 0x0809915f in Perl_av_undef () #218243 0x080ad129 in Perl_sv_clear () #218244 0x080ad378 in Perl_sv_free2 () #218245 0x080acd5f in Perl_sv_clear () #218246 0x080ad378 in Perl_sv_free2 () #218247 0x0809915f in Perl_av_undef () #218248 0x080ad129 in Perl_sv_clear () #218249 0x080ad378 in Perl_sv_free2 () #218250 0x080c79e0 in Perl_leave_scope () #218251 0x080a13a8 in Perl_pp_unstack () #218252 0x080a0bb8 in Perl_runops_standard () #218253 0x0809f652 in perl_run () #218254 0x0805ee8f in main () (gdb)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2022-12-07 09:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?