Re: Memory usage of variables in Functions/Methods
| From: | Gerard Samuel | Date: | Wed, 08 Oct 2003 03:17:18 +0000 |
| Subject: | Re: Memory usage of variables in Functions/Methods | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-165383@lists.php.net to get a copy of this message | ||
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...