in reply to Re^2: Out of Memory Error -- Possible Leak?
in thread Out of Memory Error -- Possible Leak?
I'm really confuzzled as to why this:
foreach my $value ( @$subarray ) {would eat up memory.
That line expands the contents of the array into a list (Ie. On Perls' stack). If the subarray pointed by $subarray is large, it will consume a large amount of memory to do that.
You can avoid that by indexing the array, rather than aliasing it's elements. Eg.
for my $index ( 0 .. $#$subarray ) { my $value = $subarray->[ $index ]; ... }
Or, if you need to modify the elements, substitue $subarray->[ $index ] wherever you are currently using $value.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Out of Memory Error -- Possible Leak?
by graff (Chancellor) on Dec 15, 2005 at 06:06 UTC | |
by BrowserUk (Patriarch) on Dec 15, 2005 at 07:02 UTC | |
|
Re^4: Out of Memory Error -- Possible Leak?
by Anonymous Monk on Dec 16, 2005 at 01:19 UTC | |
by BrowserUk (Patriarch) on Dec 16, 2005 at 07:08 UTC |