thagenbeek / phpquery

Automatically exported from code.google.com/p/phpquery
0 stars 0 forks source link

Memory leak on loop calling #192

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Using phpQuery in a loop process cause memory leaks, the PHP process grows at 
every new iteration. phpQuery::unloadDocuments(); doesn't help at all. Somehow 
the objects created by phpQuery must be unseted.

for ($i = 0;$i<=500;$i++) {
PhpQuery::newDocument($data, 'text/html');
//... some DOM selectors calls
phpQuery::unloadDocuments();
}

Open this in php CLI and monitor the process RAM usage

Original issue reported on code.google.com by sergi...@gmail.com on 1 Sep 2011 at 11:18

GoogleCodeExporter commented 9 years ago
same issue also. also with active php5.3 gc it has the same behaviour.

Original comment by marius.g...@googlemail.com on 1 Sep 2011 at 11:21

GoogleCodeExporter commented 9 years ago
Same here. php5.3.2, gc enabled. 

Original comment by gjorgjio...@gmail.com on 22 Sep 2011 at 4:01

GoogleCodeExporter commented 9 years ago
hmmm I'm wrong. 

with unloadDocuments there is no leak. Only when unloadDocuments is missing the 
leak occurs. 

This doesn't prevent the leak: 

for ($i = 0;$i<=5000;$i++) {
$browser = PhpQuery::newDocument($content, 'text/html');
$browser=null;
gc_collect_cycles();
}       

The PHP in this case is not aware of the leak and the leak goes over the 
memory_limit set in php.ini. 

Original comment by gjorgjio...@gmail.com on 22 Sep 2011 at 4:22

GoogleCodeExporter commented 9 years ago
That's strange because in my case phpQuery::unloadDocuments() doesn't free up 
RAM..

Original comment by sergi...@gmail.com on 7 Nov 2011 at 11:03

GoogleCodeExporter commented 9 years ago
I can confirm the memory leak. I had a few scripts where I had to call 
PhpQuery::newDocument in a loop. With time, the script eat up more and more 
RAM. I tried something similar to @gjorgjio:

while condition
    $page = PhpQuery::newDocument($content, 'text/html');
    unset($page)
    gc_collect_cycles();
end

but this doesn't help. i will try unloadDocuments at some moment and let you 
know about the results.

Original comment by tolean...@gmail.com on 5 Jun 2012 at 2:55

GoogleCodeExporter commented 9 years ago
No memory leaks by calling phpQuery::unloadDocuments() at each iteration.

Original comment by gatis.la...@gmail.com on 27 Jun 2012 at 6:29

GoogleCodeExporter commented 9 years ago
I had a memory leak in by calling phpquery in a loop (php process ~80% memory 
usage), after calling unloadDocuments everytime in the loop, it's now only 1,5% 
memory usage.

Original comment by Dietrich...@gmail.com on 17 Jul 2012 at 1:58

GoogleCodeExporter commented 9 years ago
I was experiencing problems with the phpQuery::newDocument() causing lots of 
memory usage.  I wasn't exactly calling it directly in a loop, but rather in a 
function that was being called in a loop.  Tried calling unset() on the object 
that was holding the return of phpQuery::newDocument(), but that didn't help.

I put phpQuery::unloadDocuments() at the end of my function call, and I no 
longer am seeing the "leaking" memory.

Original comment by jus...@innersync.com on 20 Sep 2012 at 1:13