There we can see $foo has an initial REFCNT (reference count) of 1 created by the file-level lexical scope, it is incremented when $r created a reference to it, and then decremented when $r goes out of scope (garbage collected because it's enclosing scope exitted and it's REFCNT dropped to 0) and would be garbage-collected once the file-scoped exits (which in this case is when the program ends). See. Matts wonderful Proxy Objects article for a more thorough review of reference counting in perl.use Devel::Peek; my $foo; Dump($foo); { my $r = \$foo; Dump($foo); } Dump($foo); __output__ SV = NULL(0x0) at 0x8107e34 REFCNT = 1 FLAGS = (PADBUSY,PADMY) SV = NULL(0x0) at 0x8107e34 REFCNT = 2 FLAGS = (PADBUSY,PADMY) SV = NULL(0x0) at 0x8107e34 REFCNT = 1 FLAGS = (PADBUSY,PADMY)
_________
broquaint
In reply to Re: Does Perl have garbage collection mechanism and how it performs?
by broquaint
in thread Does Perl have garbage collection mechanism and how it performs?
by RobCheung
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |