in reply to Re^9: sub fuction inside sub functioin?
in thread sub fuction inside sub functioin?

I don't get it!

In my example the lexical variable $inner is allocated *once* in the outer-closure. You may have plenty of cyclic refrences, but please show me how the allocated space for this *lonely* variable may cause a memory leak!?!

or do you think the space for the reference counter may leak???

Cheers Rolf

  • Comment on Re^10: sub fuction inside sub functioin?

Replies are listed 'Best First'.
Re^11: sub fuction inside sub functioin?
by ikegami (Patriarch) on Dec 08, 2008 at 13:20 UTC
    Are you talking about the original lexical code (sub outer { my $inner; ... }) or the updated one ({ my $inner; sub outer { ... } }). I sent you a message a few posts ago that I updated my post to retract my comment.
      I was talking about
      { my $inner; sub outer { $inner=sub { ... $inner->(); ... } } }.
      OK I just saw your update. IMHO this is the safest way to realize inner subs without stash side-effects and cyclic memory leaks.

      To get back to the OT, I recommend it this way.

      Cheers Rolf

        To get back to the OT, I recommend it this way.

        To get back to the OT, I stick with my original recommendation. I had already considered the alternatives before posting it and found them to leak memory and/or needlessly convoluted.

        Reader, take your pick. If you bless a hash to make an object, you have no reason to use lexicals for inner subs.