| Store | Cart

RE: [perl #125530] Freeing variables referred to by coderefs

From: Daniel Perrett <d...@sanger.ac.uk>
Thu, 2 Jul 2015 13:45:08 +0000
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


Recent Messages in this Thread
Daniel Perrett (via RT) Jul 02, 2015 11:08 am
Zefram Jul 02, 2015 01:12 pm
Daniel Perrett Jul 02, 2015 01:45 pm
Ricardo Signes Jul 03, 2015 01:28 am
James E Keenan via RT Jul 02, 2015 11:10 pm
Messages in this thread