
rgarciasuarez at gmail
Nov 13, 2006, 8:59 AM
Post #1 of 7
(373 views)
Permalink
|
|
Memory leak with s/// and hashes
|
|
Here's a small script, courtesy of an ex-coworker. When executing it, the memory usage increases, but no leak is detected by valgrind. For example, for 1000 loops, memory usage here goes from 412 to 1580. It doesn't leak with 5.8.8. Not sure how to trace this. It seems to involve hashes and substitutions. A problem with shared keys ? #!perl # usage : $0 <nb_loops> my $str1 = "My name is_BABA_ and I do a _TINY_ _WORK_\n"; my $str2 = "I work in _ENTERPRISE_. I'm very _FEELING_ and I _ACTION_.\n"; my %values1 = (BABA => " Bibi", TINY => "Small", WORK => "Job"); my %values2 = (ENTERPRISE => "xyz", FEELING => "happy", ACTION => "sleep"); sub subtitute { my ($string, $param) = @_; my $r = join '|' => keys %$param; $string =~ s/$r//g; return $string; } sub printMemSize { system("ps -C perl -o cmd=,size="); } printMemSize(); for (0 .. ( $ARGV[0] || 1 )) { $foo1 = subtitute($str1,\%values1); $foo2 = subtitute($str2,\%values2); } printMemSize(); __END__
|