note 56332 deleted from function.unset by cmb
| From: | cmb@php.net | Date: | Thu, 11 Nov 2021 22:28:36 +0000 |
| Subject: | note 56332 deleted from function.unset by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-217190@lists.php.net to get a copy of this message | ||
Note Submitter: no at spam dot com
----
In addition to what timo dot hummel at 4fb dot de said;
>For the curious: unset also frees memory of the variable used.
>
>It might be possible that the in-memory size of the PHP Interpreter isn't reduced, but your
>scripts won't touch the memory_limit boundary. Memory is reused if you declare new variables.
It might be worth adding that functions apparently don't free up memory on exit the same way
unset does..
Maybe this is common knowledge, but although functions destroys variables on exit, it (apparently)
doesn't help the memory.
So if you use huge variables inside functions, be sure to unset them if you can before returning
from the function.
In my case, if I did not unset before return, then the script would use 20 MB more of memory than if
I did unset.
This was tested with php 5.0.4 on apache 2 on windows xp, with no memory limit.
Before I did the test, I was under the impression that when you exit from functions, the memory used
inside it would be cleared and reused. Maybe this should be made clear in the manual, for either
unset() or in the chapter for functions.