The code illustrates better what I\'m asking:
function foo(){
$var = get_huge_amount_of_data();
return $var[0];
}
$s = foo();
// is memory freed her
So I know that $var gets freed at some point, but does PHP do it efficiently? Or do I manually need to unset expensive variables?
Yes, PHP makes a good job. This is a question you should never need to think about. In your case I would rather think about the moment between $var = .. and return .., because that is the moment, where you cannot avoid the memory consumption. You should try to find a solution, where you don't need to fetch the whole dataset via get_huge_amount_of_data() and then select a single item, but only the data you need.