I have a PHP script that runs in the background for a while (usually a few minutes, but it can be up to an hour or so). It contains a loop in which I need to create an object. I am currently using the same name:
while (!$job_finished) {
$x = new MyClass();
$x->doStuff();
$x->doMoreStuff();
unset ($x);
}
Since I create $ x with the same name many times, will garbage collection properly clear memory? Or should I use an array over $ x, for example
$x[$i] = new MyClass();
source
share