So thanks to some users here I got my program working but I was told maybe it has a memory leak because with certain cases it will run for a couple hours & I'll get an out of memory error. & sure enough, using Test::LeakTrace (thx to this node http://perlmonks.org/?node_id=1001200 :) ) I found that a couple lines have leaking scalars & references. I tried the -verbose option but it was way over my head, not knowing much about the guts of perl. I could post what it says if it would help. Here's the suspect block:
use Math::Polynomial::Solve qw! poly_derivative poly_roots !; # $rep is the right endpoint of the interval [0, $rep] foreach my $a (3..$rep ) { foreach my $b (2..$a-1 ) { foreach my $c (1..$b-1 ) { # expanded form of x*(x - a)*(x - b)*(x - c) # coeffs are in an array my @quartic = (1, -$a - $b - $c, $a*$b + $a*$c + $b*$c, -$a*$b +*$c, 0); my @derivative = poly_derivative(@quartic); my @zeros = poly_roots(@derivative); $haystack{"$a, $b, $c"} = \@zeros; } } }
The problem lines according to Test::LeakTrace are
my @zeros = poly_roots(@derivative);&
$haystack{"$a, $b, $c"} = \@zeros;Devel::Size tells me that, in one case anyway, the stuff that I want (the "needles" I guess) is roughly 236 bytes, but the %haystack, including all the information + references is close to 4MB! What can I do? Those two lines also happen to be the only ones containing @zeros & poly_roots, & if there's a problem with that Poly::Solve module I definitely don't want to be the one to mess with it.
PS- I've also tried Scalar::Util's weaken function on various things & it didn't seem to help. I wonder if I'm just not using it properly.
In reply to help with memory leak by crunch_this!
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |