Ah, I'm a fool!
Presumably, creating a weak reference to do the recursion should work ... and indeed it does appear to do the trick.
Thankyou very much, and apologies for the bug report.
Daniel
-----Original Message-----
From: Zefram via RT [mailto:perl...@perl.org]
Sent: 02 July 2015 14:13
To: Daniel Perrett
Subject: Re: [perl #125530] Freeing variables referred to by coderefs
Daniel Perrett wrote:
>The attached script contains a variable "$leak". If it has a false >value, an operation is performed in such a way that memory remains >constant (amount varies per system: below 1MB on an Ubuntu perl); with >a true value, it behaves as if there is a memory leak (exceeds 10MB on >the same perl).
Actually both versions leak. With $leak false it just leaks *less*.
Add system("ps u $$") inside the loop and watch VSZ gradually increasing.
>There are no cyclical references.
There is a cyclical reference: The $pathfinder sub is closed over the $pathfinder variable which contains a reference to the sub.
-zefram