http://qs1969.pair.com?node_id=1100259


in reply to Re^5: Memory leak detection
in thread Memory leak detection

There is a second way for objects not getting released that is not really a cyclic reference: If you have a subroutine that closes over a variable, the value of that variable will not get released. This is especially nasty if you're dealing with lots of callbacks (like in AnyEvent) and don't keep track of which callback closes over which variable.

Replies are listed 'Best First'.
Re^7: Memory leak detection
by andal (Hermit) on Sep 11, 2014 at 12:20 UTC

    Strictly speaking this is not a "leak". The variables are still accessible from the code. They will get released when the subroutine goes out of scope. Of course, if one of subroutines references variable that keeps reference to that subroutine, then neither code, nor the variable will be released, but this is circular reference again :)

Re^7: Memory leak detection
by runnerup (Novice) on Sep 12, 2014 at 14:48 UTC
    Thanks for your reply.
    > If you have a subroutine that closes over a variable, the value of that variable will not get released

    What do you mean by "subroutine that closes over a variable"?