in reply to Re^2: Freeing memory, revisited (Linux)
in thread Freeing memory, revisited (Linux)
Nice theorySimply the truth.
In your run-time example, a different mechanism causes the allocations to be retained. Every sub-expression that returns a result has a "pad temp" allocated to it to store the temporary result. The values in the pad temp are retained until the sub is freed, but they are re-used. i.e. in the following:
a single temp will be stored within f's pad. On the first call it will hold a scalar of length 100_000, which gets retained. On the second call, the scalar is shrunk to length 5 (but not freed), and on the third call the scalar is realloced to grow to 200_000, and finally freed when the sub f is destroyed.sub f { return "x" x $_[0] } f(100_000); f(5); f(200_000);
Dave.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Freeing memory, revisited (Linux)
by Eliya (Vicar) on May 05, 2011 at 15:47 UTC | |
by dave_the_m (Monsignor) on May 05, 2011 at 16:44 UTC |