ID: 42158 Comment by: judas dot iscariote at gmail dot com Reported By: chabrol at vfnm dot de Status: Open Bug Type: PCRE related Operating System: Linux PHP Version: 5CVS-2007-07-31 (snap) New Comment:
There is no memory leak, those leaks are reported at script shutdown by the Zend Engine. to fix your problem do this preg_match("/bar/", (string)$xml->name); yes, cast it to string. Previous Comments: ------------------------------------------------------------------------ [2007-07-31 13:19:38] chabrol at vfnm dot de little imprecision fix: Memory is only increasing until hitting configured memory if you replace the limited for-loop by a while(true) ... ------------------------------------------------------------------------ [2007-07-31 13:13:45] chabrol at vfnm dot de Description: ------------ If you use a SimpleXMLElement as parameter for preg_match or preg_match_all, memory is lost. P.S.: If you cast the parameter explicit with (string)$xml->name memory usage doesn't increase. So i suppose it's an problem related to internal casting. Reproduce code: --------------- <?php $xml = simplexml_load_string("<root><name>foo</name></root>"); for ($i=1; $i<=20; $i++) { preg_match("/bar/", $xml->name); // or preg_match_all("/bar/", $xml->name, $matches); echo "Memory usage after $i iterations: " . memory_get_usage() . "\n"; } ?> Expected result: ---------------- I would expect an more or less equal memory usage. Actual result: -------------- Memory usage is constantly increasing until hitting configured memory limit ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=42158&edit=1