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


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

Other than cyclic references (which I don't think could exist in my code), do you know what could cause this to happen?
I would think that if the reference count is 0, that the objects would be deleted.
What approach should I use to find the problem?

Replies are listed 'Best First'.
Re^5: Memory leak detection
by andal (Hermit) on Sep 11, 2014 at 07:08 UTC
    Other than cyclic references (which I don't think could exist in my code), do you know what could cause this to happen?

    Well, circular references do not have to be direct. There are lots of subtle ways for creating them. That makes finding them very complex at times.

    I don't know about any other reason for perl to keep unused objects around.

      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.

        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 :)

        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"?