FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


unsetting variables - when to and when not to





defnet
Yo guys,
I try to unset most variables that I know I will no longer need to minimize the server load. However, I wanna know if it is still necessary to unset the variables that you declare within a function.

Aren't those variables who were declared within a function, automatically unset whenever the function completes?

BTW: Is unsetting variables really a good practice or is it not really necessary in most cases...
Star Wars Fanatic
It's not really necessary, and yea, the variables in functions are automatically unset once the function is finished running.

If you have a lot of variables, or you want to use a variable again without having to worry about previous contents, you can use the unset() method.
Mgccl
Usually you will only need to unset() a variable when your memory is too low
for example, I have only used it in something involved images, but generally images have a imagedestroy() function.

Sometimes, there is a possibility you create a HUGE array (3000 key) and going to use up all your memory(on some machines, only 8MB is allowed for PHP), then you have to use the unset() when you don't need the array(free the memory)
AOP Web Development
as a practice for good programming it is better to free all the variables that are not usable inorder not to suffer the server of the website.
Related topics
PHP Includes and Variables?
Problem with session variables
Separating contents of MySQL row and put them in variables?
problem adding variables in javascript
using variables
150 frih to make this SIMPLE script
How to make Global Variables with PHP?
Javascript Variables FRIH$ to Debug
Urls into variables
ImageMagick path and variables, GD support?
Catching unused variables
session variables
The matrix online hints and tips
Session variables versus page variables
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.