in reply to Re^3: help with memory leak
in thread help with memory leak

Changing the code doesn't change whether or not leaktrace detects any leaks, including putting the subroutine in the innermost loop. How could I do this without %haystack, since if there are actually no memory leaks I think that would probably be much less of a drag on my computer? & simpler is better imho. I'm open to anything that would work. The function no_leaks_ok says there aren't any leaks so I'm with you there but leaktrace -verbose says

leaked REF(0x24810cc) from quarticmod.pl line 42.<BR> 41: 42: $haystack{"$x, $y, $z"} = [ 43: poly_roots( SV = IV(0x24810c8) at 0x24810cc REFCNT = 1 FLAGS = (ROK) RV = 0x248101c SV = PVAV(0x247e750) at 0x248101c REFCNT = 1 FLAGS = () ARRAY = 0x24fdbe4 FILL = 2 MAX = 2 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = NV(0x1989d9c) at 0x248102c REFCNT = 1 FLAGS = (NOK,pNOK) NV = 2.6180339887499 Elt No. 1 SV = NV(0x1989f8c) at 0x248103c REFCNT = 1 FLAGS = (NOK,pNOK) NV = 1.5 Elt No. 2 SV = NV(0x1989f9c) at 0x248104c REFCNT = 1 FLAGS = (NOK,pNOK) NV = 0.381966011250106 leaked SCALAR(0x248104c) from quarticmod.pl line 42. 41: 42: $haystack{"$x, $y, $z"} = [ 43: poly_roots( SV = NV(0x1989f9c) at 0x248104c REFCNT = 1 FLAGS = (NOK,pNOK) NV = 0.381966011250106 leaked SCALAR(0x248103c) from quarticmod.pl line 42. 41: 42: $haystack{"$x, $y, $z"} = [ 43: poly_roots( SV = NV(0x1989f8c) at 0x248103c REFCNT = 1 FLAGS = (NOK,pNOK) NV = 1.5 leaked ARRAY(0x248101c) from quarticmod.pl line 42. 41: 42: $haystack{"$x, $y, $z"} = [ 43: poly_roots( SV = PVAV(0x247e750) at 0x248101c REFCNT = 1 FLAGS = () ARRAY = 0x24fdbe4 FILL = 2 MAX = 2 ARYLEN = 0x0 FLAGS = (REAL) Elt No. 0 SV = NV(0x1989d9c) at 0x248102c REFCNT = 1 FLAGS = (NOK,pNOK) NV = 2.6180339887499 Elt No. 1 SV = NV(0x1989f8c) at 0x248103c REFCNT = 1 FLAGS = (NOK,pNOK) NV = 1.5 Elt No. 2 SV = NV(0x1989f9c) at 0x248104c REFCNT = 1 FLAGS = (NOK,pNOK) NV = 0.381966011250106 The size of haystack is 129 bytes. The size of haystack including references is 265 bytes. The size of wants is 36 bytes. The size of wants including references is 36 bytes.

Replies are listed 'Best First'.
Re^5: help with memory leak
by kcott (Archbishop) on Apr 18, 2013 at 19:37 UTC

    Going back to the Test::LeakTrace documentation, specifically the part I quoted in my original response, you'll see: "Thus, to trace true leaks, no_leaks_ok() ...". So, if the documentation is to be believed, and no_leaks_ok() is showing no leaks with the modified code, then it would follow that you now have no true leaks. Problem solved!

    In your code, the only use you show for %haystack is to conditionally populate @wants. So, rather than coding:

    my %haystack; ... $haystack{"$x, $y, $z"} = [ poly_roots( ... my @wants = grep { is_approximately_an_integer( @$_ ) } values %haysta +ck;

    I'm suggesting you do something like this (which does away with %haystack altogether):

    my @wants; ... push @wants, grep { is_approximately_an_integer( @$_ ) } [ poly_roots( ...

    -- Ken