in reply to Garbage collection at subroutine return
Sure, why not declare the hash outside of the subroutine, so that its scope doesn't cause it to be garbage-collected? You're obviously not using the hash anyway:
#!/usr/bin/perl -w use strict; use warnings; my $func_done; my $func_return; my $max=1000000; my %myhash; DoIt($max); $func_return = (times)[0]; printf "Size of myhash is %d\n", 0 + keys %myhash; printf "Return took %.4f CPU seconds\n", $func_return - $func_done; sub DoIt{ my $limit=shift; my $i; foreach $i (0..$limit){ $myhash{$i}=1; } $func_done = (times)[0]; return; }
But it sounds like you may have an XY problem. What is your real goal here?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Garbage collection at subroutine return
by tcarmeli (Beadle) on Feb 15, 2007 at 13:53 UTC | |
by RMGir (Prior) on Feb 15, 2007 at 15:14 UTC | |
by derby (Abbot) on Feb 15, 2007 at 17:26 UTC | |
by RMGir (Prior) on Feb 16, 2007 at 15:06 UTC | |
by GrandFather (Saint) on Feb 15, 2007 at 19:48 UTC |