in reply to What's the weaken here for?
I don't see any difference with or without weaken $wrapper;,what's it there for?
Where exactly?
How are you checking to see a difference?
$ perl -MDevel::Peek -MScalar::Util=weaken -le " sub fudge { my $f = s +ub { print 1; }; Dump($f); weaken $f; Dump($f); $f; } $f = fudge(); $ +f->(); Dump($f);" SV = IV(0x3f8d18) at 0x3f8d1c REFCNT = 1 FLAGS = (PADMY,ROK) RV = 0x3f8cfc SV = PVCV(0x9a263c) at 0x3f8cfc REFCNT = 2 FLAGS = (PADSTALE,PADMY,ANON,WEAKOUTSIDE,CVGV_RC) COMP_STASH = 0x3f8b5c "main" START = 0x9d9178 ===> 0 ROOT = 0x9d913c GVGV::GV = 0x99a9f4 "main" :: "__ANON__" FILE = "-e" DEPTH = 0 FLAGS = 0x490 OUTSIDE_SEQ = 272 PADLIST = 0x99aa24 PADNAME = 0x99aae4(0x9a7d1c) PAD = 0x3f8d0c(0x9a7b44) OUTSIDE = 0x99aa74 (fudge) SV = IV(0x3f8d18) at 0x3f8d1c REFCNT = 1 FLAGS = (PADMY,ROK,WEAKREF) RV = 0x3f8cfc SV = PVCV(0x9a263c) at 0x3f8cfc REFCNT = 1 FLAGS = (PADSTALE,PADMY,RMG,ANON,WEAKOUTSIDE,CVGV_RC) MAGIC = 0x3fff2c MG_VIRTUAL = &PL_vtbl_backref MG_TYPE = PERL_MAGIC_backref(<) MG_OBJ = 0x3f8d1c COMP_STASH = 0x3f8b5c "main" START = 0x9d9178 ===> 0 ROOT = 0x9d913c GVGV::GV = 0x99a9f4 "main" :: "__ANON__" FILE = "-e" DEPTH = 0 FLAGS = 0x490 OUTSIDE_SEQ = 272 PADLIST = 0x99aa24 PADNAME = 0x99aae4(0x9a7d1c) PAD = 0x3f8d0c(0x9a7b44) OUTSIDE = 0x99aa74 (fudge) 1 SV = IV(0x9c2e40) at 0x9c2e44 REFCNT = 1 FLAGS = (ROK) RV = 0x3f8cfc SV = PVCV(0x9a263c) at 0x3f8cfc REFCNT = 2 FLAGS = (PADSTALE,PADMY,RMG,ANON,WEAKOUTSIDE,CVGV_RC) MAGIC = 0x3fff2c MG_VIRTUAL = &PL_vtbl_backref MG_TYPE = PERL_MAGIC_backref(<) COMP_STASH = 0x3f8b5c "main" START = 0x9d9178 ===> 0 ROOT = 0x9d913c GVGV::GV = 0x99a9f4 "main" :: "__ANON__" FILE = "-e" DEPTH = 0 FLAGS = 0x490 OUTSIDE_SEQ = 272 PADLIST = 0x99aa24 PADNAME = 0x99aae4(0x9a7d1c) PAD = 0x3f8d0c(0x9a7b44) OUTSIDE = 0x99aa74 (fudge)
As you notice, REFCNT doesn't change :)
Yeah, that is not a use case for weaken, you use weaken when you have circular references, say
my $foo = { kid => { } }; $foo->{kid}{parent} = $foo; weaken $foo->{kid}{parent};
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: What's the weaken here for?
by PerlOnTheWay (Monk) on Jan 20, 2012 at 03:11 UTC | |
by BrowserUk (Patriarch) on Jan 20, 2012 at 03:16 UTC | |
by Anonymous Monk on Jan 20, 2012 at 03:38 UTC | |
by PerlOnTheWay (Monk) on Jan 20, 2012 at 05:44 UTC | |
by Anonymous Monk on Jan 20, 2012 at 07:55 UTC |
In Section
Seekers of Perl Wisdom