Question

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?
Was it helpful?

Solution

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top