andal has asked for the wisdom of the Perl Monks concerning the following question:
Somehow, in the last few days I stumble more over perl peculiarities, than in last few years :)
Again. I wanted to check how perl handles memory when I use substr($a, 0, 1) = ''. So I've used Devel::Peek to try the following code
To my surprise it has produced the outputuse Devel::Peek 'Dump'; use strict; my $a = "test"; substr($a, 0, 2) = ''; Dump $a;
SV = PV(0x22d3088) at 0x22f1968 REFCNT = 2 FLAGS = (PADMY,POK,OOK,pPOK) OFFSET = 2 PV = 0x22e26b2 ( "t\2" . ) "st"\0 CUR = 2 LEN = 6REFCNT is 2! Why? At first I thought, that this has something to do with the Devel::Peek, but after checking few other situations, I'm sure, that this happens only when I use substr to modify the content of the variable. Is there some internal reason for incrementing the reference count for the variable, or it is just a bug?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: is this a memory leak or do I miss something?
by Anonymous Monk on Oct 28, 2010 at 08:13 UTC | |
|
Re: is this a memory leak or do I miss something?
by jwkrahn (Abbot) on Oct 28, 2010 at 08:52 UTC | |
by Anonymous Monk on Oct 28, 2010 at 10:21 UTC | |
by andal (Hermit) on Oct 28, 2010 at 11:15 UTC | |
by XooR (Beadle) on Oct 28, 2010 at 09:57 UTC |