Does the code need to delete all used variables at the end? For example:
$test = date("dmY"); echo $test; unset($test); // Нужна ли эта строка?
Does the code need to delete all used variables at the end? For example:
$test = date("dmY"); echo $test; unset($test); // Нужна ли эта строка?
It all depends on what you are doing next and have done before. If you create a simple object (or variable) - then the meaning of it to destroy? The garbage collector will do everything himself. If you are creating a voluminous object now and further, you also plan to create something bulky (for example, in a cycle) and at the same time fear that your memory will become a girl (sorry girls, you suffer from it), then you can also call the collector. You can read more about destructors. They write little about them, because they are rarely used, but what if this is the case?))
Still, if this variable is used in some part of the code, which is a separate logical block, this block can be formed as a function with its local variables.
When the function runs, all its local variables will free up memory.
It is necessary to clean it only if the variable with the volume of information contained in it exceeds 100kb and more, although there is already your choice, I am from personal experience. It happens that during the execution of the script can eat and 300kb, or even 2MB. But your code can be simplified:
echo date("dmY");
If the received date is not needed anywhere else.
Not necessary.
Source: https://ru.stackoverflow.com/questions/66167/
All Articles