in reply to Re^3: out of memory problem
in thread out of memory problem
but it does allocate new memory before running bar, even though it could reuse $var's memory for $var2.
No, that would defy the optimization of not deallocating it in the first place.
For Perl to know when $var is not currently being used, it would have to 1) place $var on a free list when it stops being used and 2) remove it from the free list when $var is in use again. Those two operations are known as deallocation and allocation, exactly what the optimization is trying to avoid!
Keep in mind that each variable consists of two memory blocks, three if they have a string buffer associated with them. And that's just for non-magical scalars. A lot of CPU time is being saved.
One question remains: When does perl free memory?
Anon SVs are freed. SVs that become anon (such as return values) are freed. SVs passed to undef have their attached buffer freed.
Keep in mind that all of this is the result of an (undocumented?) optimization. It shouldn't be relied upon. It's just that you can't rely on it not happening.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: out of memory problem
by betterworld (Curate) on Sep 13, 2008 at 20:44 UTC | |
by ikegami (Patriarch) on Sep 13, 2008 at 21:26 UTC | |
by BrowserUk (Patriarch) on Sep 13, 2008 at 21:37 UTC |