Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: Memory leaks and circular references

by jdrago_999 (Hermit)
on Sep 07, 2008 at 00:56 UTC ( [id://709572]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Memory leaks and circular references
in thread Memory leaks and circular references

You are correct.

Execute the following on both Perl 5.8.8 and Perl 5.10.0 and I get different results.

Under Perl 5.8.8, I leak no memory and everything runs fine.
john@john-laptop:~/Projects/Cloud-T3n$ time perl refs.pl 1000000/1000000 real 0m53.021s user 0m10.753s sys 0m1.912s
Uses 200Mb of RAM.
john@john-laptop:~/Projects/Cloud-T3n$ time /usr/bin/perl refs.pl 1000000/1000000 real 0m58.048s user 0m11.989s sys 0m1.672s
Uses 2,476Kb RAM.

Please Note that I did as many folks right here have recommended and compiled my Perl 5.10.0 from the source on CPAN, without threads.

Perhaps we'll see some discussion on that here as well.

For reference, this is the exact code I am running:
package Top; sub new { my $class = shift; my $s = bless { }, $class; $s->{bottom} = Bottom->new( $s ); return $s; } #===================================== package Bottom; use Scalar::Util 'weaken'; sub new { my ($class, $top) = @_; my $s = bless { top => $top }, $class; weaken($s->{top}); return $s; } #===================================== package main; use Devel::Cycle; for( 1...1_000_000 ) { print "\r$_/1000000"; my $top = Top->new(); my $bottom = $top->{bottom} or die "NO BOTTOM!"; $top = $bottom->{top} or die "NO TOP!"; find_cycle( $top ); find_cycle( $bottom ); }

Replies are listed 'Best First'.
Re^5: Memory leaks and circular references
by jdrago_999 (Hermit) on Sep 07, 2008 at 01:05 UTC

    FIXED!

    It turns out that by adding this to class Top the memory leakage (on Perl 5.10.0) went away.:
    sub DESTROY { my $s = shift; undef(%$s) }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2026-02-18 06:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.