Indeed...

use strict; use warnings; use Test::More; use Scalar::Util qw(weaken isweak); use Devel::Refcount qw(refcount); my $A = bless {}, 'Monkey'; is(refcount($A), 1, 'an object has a refcount'); my $B = $A; is(refcount($A), 2, 'additional ref to the object increases the refcou +nt'); $B = undef; is(refcount($A), 1, 'removing a ref to the object decreases the refcou +nt'); do { my $C = $A; is(refcount($A), 2, 'reference in a scope increases refcount'); }; is(refcount($A), 1, '$C fell out of scope, so decreased ref count'); my $D = $A; is(refcount($A), 2, 'another ref which will increase ref count'); weaken $D; is(refcount($A), 1, 'weakening the ref means it is not included in the + ref count'); ok($A == $D, 'yet $A and $D are still the same object'); my $destroyed = 0; sub Monkey::DESTROY { $destroyed++ }; $A = undef; is($destroyed, 1, 'undefining $A destroyed the object; $D was a weak r +ef so did not prevent destruction'); ok(!defined $D, '$D is now undefined'); done_testing;
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
/tt); my $B = $A; is(refcount($A), 2,

In reply to Re^2: Timing of garbage collection by tobyink
in thread Timing of garbage collection by dd-b

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.