I'm curious about using of unset() language construct just about everywhere, where I took memory or declare some variables (regardless of structure).
I mean, when somebody declares variable, when should it really be left for GC, or be unset()?
Example 1:
<?php
$buffer = array(/* over 1000 elements */);
// 1) some long code, that uses $buffer
// 2) some long code, that does not use $buffer
?>
- Is there any chance, that
$buffermight affect performance of point 2? - Am I really need (or should) to do
unset($buffer)before entering point 2?
Example 2:
<?php
function someFunc(/* some args */){
$buffer = new VeryLargeObject();
// 1) some actions with $buffer methods and properties
// 2) some actions without usage of $buffer
return $something;
}
?>
- Am I really need (or should) to do
unset($buffer)withinsomeFunc()s body before entering point 2? - Will
GCfree all allocated memory (references and objects included) withinsomeFunc()s scope, when function will come to an end or will findreturnstatement?
I'm interested in technical explaination, but code style suggestions are welcome too.
Thanks.