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!

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.