I use PHPQuery (HTML parser) in a loop and each time undoing the previous document using phpQuery::unloadDocuments() . The cycle is simplified to:
while(...){ $doc="parsed stuff"; ... unset($doc); }
However, a memory leak occurs due to a lack of script memory after a while. After searching the Internet, someone recommended that in order to avoid memory leak, I should wrap it in a function, so I changed it to the following:
function r(){ $doc="parsed stuff"; ... unset($doc); } while(...) r();
Now the memory leak has stopped. Why is this?
source share