Does PHP free local variables immediately after the function ends?

后端 未结 4 1980
迷失自我
迷失自我 2020-12-19 03:59

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         


        
4条回答
  •  独厮守ぢ
    2020-12-19 04:39

    Yes it is because $var is declare on stack and get clear as soon it goes out of scope

    You can refer this https://stackoverflow.com/a/5971224/307157

提交回复
热议问题