Weak references are deleted BEFORE the DESTROY method of the object they point to runs?

No.

$ perl -MScalar::Util=weaken -MDevel::Peek -wE' my $y; sub DESTROY { Dump($y,0); Dump($_[0],1); } { my $x = bless({}); $y = $x; weaken($y); } ' SV = IV(0x99a738c) at 0x99a7390 <-- $y REFCNT = 2 FLAGS = (PADMY,ROK,WEAKREF) <-- Still a reference (ROK) RV = 0x998c768 <-- Still referencing %$x SV = IV(0x998c8a4) at 0x998c8a8 <-- $x REFCNT = 1 FLAGS = (ROK,READONLY) RV = 0x998c768 SV = PVHV(0x99917a8) at 0x998c768 <-- %$x REFCNT = 1 FLAGS = (OBJECT,OOK,SHAREKEYS) STASH = 0x998c658 "main" ARRAY = 0x99a6210 KEYS = 0 FILL = 0 MAX = 7 RITER = -1 EITER = 0x0 BACKREFS = 0x99a7390 <-- %$x is weakly ref-ed by $y SV = IV(0x99a738c) at 0x99a7390 REFCNT = 2 FLAGS = (PADMY,ROK,WEAKREF) RV = 0x998c768

Sorry, no time to look into your code today.

Update: I was misusing weaken. Fixed.


In reply to Re: weak refs deleted while target of ref still live? by ikegami
in thread weak refs deleted while target of ref still live? by patcat88

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.