in reply to Re: Iterative anonymous subroutines
in thread Iterative anonymous subroutines
Closures that enclose themself represent a reference cycle which is a.k.a. a memory leak. If you need a self referencing sub you should localize a glob to do it. Ie:
local *recursive=sub { ... recursive(...); };
This keeps the self references "soft" and means that when it goes out of scope the sub will be freed. Doing it via lexicals is not correct
my $recursive; $recursive=sub{ ... $recursive->(...); };
as it will leak. (Meaning the sub referenced by $recursive will not be freed until global destruction.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Iterative anonymous subroutines
by Anonymous Monk on Dec 14, 2005 at 17:53 UTC |