calin has asked for the wisdom of the Perl Monks concerning the following question:
Quick question: does keeping a reference to an array element or hash value prevent the freeing of the container object when all the "direct" references to it go away? My impression (90% sure) is that the answer is no - elements do not impose "upward reference-counting" to their container (it would be blatantly anti-DWIMish and a severe source of memory leaks) - but I want to be 100% sure.
# create a reference to an anon array my $aref = [1..100]; # take a reference to one of its elements my $elem_ref = \$aref->[50]; # drop the array reference undef $aref; # is the anon array still gobbling up memory in a zombie state?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Query on refcounting with container objects
by dragonchild (Archbishop) on Jul 29, 2004 at 19:21 UTC | |
by Joost (Canon) on Jul 29, 2004 at 19:48 UTC | |
by gmpassos (Priest) on Jul 30, 2004 at 05:02 UTC | |
|
Re: Query on refcounting with container objects
by fergal (Chaplain) on Jul 29, 2004 at 19:59 UTC |