Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Lost anonymous subs

by kappa (Chaplain)
on Dec 09, 2004 at 15:30 UTC ( [id://413584]=note: print w/replies, xml ) Need Help??


in reply to Re: Lost anonymous subs
in thread Lost anonymous subs

Thanks for information! Things got clearer. And what about closure behaviour? The sub WILL need a copy of @arr, won't it? I cannot understand what «a pointer to the current binding of @arr» is, pardon my ignorance, the term is not in perlref or perlsub :(
--kap

Replies are listed 'Best First'.
Re^3: Lost anonymous subs
by diotalevi (Canon) on Dec 09, 2004 at 15:33 UTC
    This is all perl internals, perlguts stuff. The CV you get in $code has an ->OUTSIDE C pointer to the PADLIST that @arr lives in and then the compiled code has a note on which index in that PADLIST it is suppposed to access the @arr at. So it isn't a copy. The code in $code works with the real, original @arr, not a copy.
      Please, say that the comments down there in the code are right and I will rest calm, thankful and a bit more knowledgable :)
      my $code; { my @arr = (9) x 1000_000; $code = sub { @arr }; } # here @arr got out of the scope but is not freed as # there's a ref from inside $code closure # which enables $code do things with the array when called undef $code; # only now that million of nines has gone away # it always existed in exactly one copy
      --kap

        Your comments were unintelligble

        Here is what happens. Your million nines will continue to stick around as long as $code does. Once you lose the last link to $code then your million nines will also be gone.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://413584]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2024-04-18 17:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found