As a rule, PHP software is not written in such a way as to be able to release memory. Instead, the software relies on the fact that it will most likely only work for a second or two until completion, thereby clearing the memory.
When you run such tests, you are likely to get a memory leak in the main application. Add additional memory checks around functions called by the code, and then around functions that call these functions, etc., until you find the culprit.
In my experience, the problem, as a rule, is to reuse the object variable in a loop:
function f() { foreach ($list as $item) { $x = new C($item); $x->doStuff(); } }
Usually, when "f" is completed, all memory is cleared. But PHP is stupid, so it computes this by looking at local variables or something like that, because only the last $ x will be cleared. Those that were created before in this loop will only flow until the script exits.
If this is - in fact - a problem, you can fix it by using unset in the variable before reusing it.
$x = new C($item); $x->doStuff(); unset($x);
rich remer
source share