Re: Memory usage of variables in Functions/Methods

From: Date: Wed, 08 Oct 2003 03:02:27 +0000
Subject: Re: Memory usage of variables in Functions/Methods
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-165381@lists.php.net to get a copy of this message
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. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'

« previous php.general (#165381) next »