in reply to Re^3: Memory leaks and circular references
in thread Memory leaks and circular references
Uses 200Mb of RAM.john@john-laptop:~/Projects/Cloud-T3n$ time perl refs.pl 1000000/1000000 real 0m53.021s user 0m10.753s sys 0m1.912s
Uses 2,476Kb RAM.john@john-laptop:~/Projects/Cloud-T3n$ time /usr/bin/perl refs.pl 1000000/1000000 real 0m58.048s user 0m11.989s sys 0m1.672s
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 | |
by Joost (Canon) on Sep 07, 2008 at 01:36 UTC |