문제

suppose I do this

function lol(){
  require_once('somefile.php');
}

lol();
  1. Once lol() finishes executing, will the memory consumed by the require command be freed up?
  2. If not, how can I manually free up memory consumed by the require? IE. is there a function to "unrequire" a file?
도움이 되었습니까?

해결책

It depends on what somefile.php will contain. Variables can be freed using unset() on all(!) references of the variable. However, they got "really" freed after the next run of the garbage collector. You can trigger the garbage collector manually but in most situations it is better to let it "just do its work" on its own.

Functions , classes and constants can't be freed once they have been created, however closures can (as they are like variables).

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top