On Thu Nov 08 15:38:43 2018, justincase wrote:
Show quoted text> This is a similar bug to that present in Algorithm::Permute and
> Algorithm::FastPermute:
>
https://rt.cpan.org/Ticket/Display.html?id=126027#txn-1799090
>
> forsetproduct calls it's block repeatedly using MULTICALL, but if the
> block creates any temporary variables, they are not cleaned up until
> after forsetproduct returns. This can result in OOM (out of memory).
> It can be resolved by placing the call to MULTICALL in a pseudoblock,
> i.e. enclosing it in ENTER/LEAVE.
Set::Product::XS would have the same bug. It is also present in every XS iterator in MPU.
If I understand correctly, this isn't so much a leak as it is a mass free when the iterator exits. Which might be a very long time.
I believe the builtin map {} function has the same issue, or at least it did a year ago. It requires a little cleverness to make sure the effect isn't dwarfed by the input list.
A test for this ticket:
perl -Mntheory=:all -E 'my @array=([0..50],[1..100],[1..100],[1..100]); for (1..100000) { forsetproduct { my $str=join "",@_; } @array; }'
shows this grow to ~200MB over ~30 seconds then hold steady. Using the ENTER/LEAVE wrapper sees it right away at ~7MB and hold steady.
Preliminary fix on github.