ID: 42158 Comment by: ibapty 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:
I can vouch for the workaround based on a similar issue (see http://bugs.php.net/bug.php?id=41911) I encountered. Unfortunately that bug got marked as bogus with a similar explaination. I accept that in 99% of uses of PHP where script shutdown occurs that this type of memory leak is acceptable. However, in my case I am using PHP persistently with the win32service module (php.net/win32service). In the end I have had to setup a routine to restart the service every few minutes to workaround this type of memory leak instead of trying to track them all down. Previous Comments: ------------------------------------------------------------------------ [2007-07-31 23:04:51] judas dot iscariote at gmail dot com 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. ------------------------------------------------------------------------ [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