note 56332 added to function.unset
| From: | no at spam dot com | Date: | Tue, 30 Aug 2005 22:22:38 +0000 |
| Subject: | note 56332 added to function.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94452@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.unset.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56332
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56332&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56332&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56332&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56332&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56332&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56332&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56332&report=yes
Search -- http://master.php.net/manage/user-notes.php