in reply to Re^5: Tracking down an Lvalue bug?
in thread Tracking down an Lvalue bug?
Related to ref to read-only alias ... why??
I don't think so.
This demonstrates the problem (bug):
perl -E"$x=chr(0); $x x= 100e6; <>; $r = \substr $x, 50e6; <>"
Watch the process memory with ProcessManager:
All that's changes is that it has taken a substr ref to the second half of the string.
I suspect it is a result of this "fix".
But I believe that fix is wrong, and that the original bug is spurious. (At least in part.)
If you do this:
my $ref; { my $string = "123"; $ref = \$string; } ## Here $string persists.
No one is surprised that (the memory allocated to) $string persists beyond the block.
Why should this be any different:
my $ref; { my $string = "123"; $ref = \substr $string, 1, 1; } ## This was the (IMO false) "bug" scenario.
In this case -- when the string goes out of scope -- I could make arguments for 3 possible outcomes:
$ref continues to refer (directly) to the memory allocate to $string.
Those parts of $string outside of $ref are inaccessible and irrecoverable until $ref is GC's.
Probably difficult to orchestrate.
At which point the extraneous (pre and/or post fix) bits of $string are GC'd leaving $ref pointing at just that which it references.
This would require retaining a pointer back to 'parent' string with the lvalue ref, and when the lvalue magic fires it checks the refcount of its parent.
If that refcount is 1 -- meaning it holds the only reference to it, it frees off the extraneous parts of the parent.
Of the three, I'd prefer C, but would find A completely in keeping with Perl's philosophy.
Duplicating the referenced memory of every lvalue ref and the having to copy it back each time it is modified -- just to cover off a really obscure scenario that is at worst, only mildly anomalous -- is crazy.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Tracking down an Lvalue bug? (!fix)
by tye (Sage) on Mar 20, 2012 at 14:05 UTC | |
|
Re^7: Tracking down an Lvalue bug?
by ikegami (Patriarch) on Mar 21, 2012 at 01:30 UTC | |
by BrowserUk (Patriarch) on Mar 21, 2012 at 01:56 UTC | |
by ikegami (Patriarch) on Mar 21, 2012 at 02:01 UTC | |
by BrowserUk (Patriarch) on Mar 21, 2012 at 02:32 UTC | |
|
Re^7: Tracking down an Lvalue bug?
by ikegami (Patriarch) on Mar 21, 2012 at 03:35 UTC | |
by BrowserUk (Patriarch) on Mar 23, 2012 at 01:14 UTC |