We have a serious memory leak in one of our regular scripts that quickly destroy free memory on the server. Despite many hours of research and experimentation, I could not even go into it.
Here is the code:
echo '1:'.memory_get_usage()."\n";
ini_set('memory_limit', '1G');
echo '2:'.memory_get_usage()."\n";
$oXML = new DOMDocument();
echo '3:'.memory_get_usage()."\n";
$oXML->load('feed.xml');
echo '4:'.memory_get_usage()."\n";
$xpath = new DOMXPath($oXML);
echo '5:'.memory_get_usage()."\n";
$oNodes = $xpath->query('//feed/item');
echo '6:'.memory_get_usage()."\n";
unset($xpath);
echo '7:'.memory_get_usage()."\n";
unset($oNodes);
echo '8:'.memory_get_usage()."\n";
unset($oXML);
echo '9:'.memory_get_usage()."\n";
And here is the conclusion:
1:679016
2:679320
3:680128
4:680568
5:681304
6:150852408
7:150851840
8:34169968
9:34169448
As you can see, when we use xpath to load nodes into an object, memory usage jumps from 681 304 to 150 852 408. I am not very worried about this.
My problem is that even after the destruction of the $ oNodes object, we are still stuck using memory 34,169,968.
, , PHP, , script. free -m , 3,295 , 5,226 , . 2 , script, , .
SimpleXML , . , , :
XML xpath php,
DOMDocument/Xpath -
DOMDocument PHP
, - , .
UPDATE 11/10: , . , 30 . , , , .
, PHP 5.3.15 Apache 2.2.3 Red Hat 5.11. , - , . .