darren chamberlain <[EMAIL PROTECTED]> writes: > * Joe Schaefer <[EMAIL PROTECTED]> [2002-07-09 12:47]: > > Dave Rolsky <[EMAIL PROTECTED]> writes: > > > On 8 Jul 2002, Joe Schaefer wrote: > > > If I do this: > > > > > > my $x = shift; > > > $x = make_something_from($x); > > > > > > then it seems like the original $x should go out of scope when it is > > > assigned to, so its refcount should stay at 1. > > ^^^^^^ > > > > Right, it should stay at 1. But all bets are off when > > $x is has magic and make_something_from() is an XS sub :-). > > But the leak is not with $x, it's with what $_[0] is; $x is just a > reference to that, and the reassignment in the second line should > reassign $x, and decrement the ref count for what $x is pointing to at > that point. So, it all depends on what make_something_from() does with > the $x's referent.
I don't think it's as simple as that- THIS LEAKS: my $r = shift; $r = Apache::Request->new($r); my $r = shift; $r = Apache::Request->new($_) for $r; DOES NOT LEAK: my $apr = Apache::Request->new(shift); my $r = shift; my $apr = $r; # $r and $apr have the same referent now right? $apr = Apache::Request->new($r); my $r = shift; my $apr = Apache::Request->new($r); my $r = shift; $r = Apache::Request->new($_) for map $_, $r; Somehow the assignment operator MUST be involved in the leak here. (You only get a leak when the *same* reference (*SV) is on both sides of the assignment). -- Joe Schaefer