Robert Cummings wrote:

On Tue, 2003-10-07 at 22:44, Gerard Samuel wrote:


The question is what happens to local variables when the code leaves a function/method
as far as memory is concerned.
Does it *silently* unset (free the allocated memory) the local variables, or does it make sense to hardcode
unset() to garbage these local variables?
Thanks


function foo()
{
$bar = 'some large value';
unset($bar);
}
---------
function foo()
{
$bar = 'some large value';
}



AFAIK when the reference count (both explicit and implicit due to copying optimizations) hits 0, the variable is deleted. Thus within a function if you declare the variable within the function and it isn't referenced anywhere else, then it is destroyed when the function's context is destroyed.

Thanks, pretty much what I was looking for...

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to