#35258 [NEW]: preg_replace() doesn't release memory

From: Date: Thu, 17 Nov 2005 11:22:26 +0000
Subject: #35258 [NEW]: preg_replace() doesn't release memory
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-88358@lists.php.net to get a copy of this message
From: mfischer@php.net Operating system: Linux PHP version: 4.4.1 PHP Bug Type: Performance problem Bug description: preg_replace() doesn't release memory Description: ------------ preg_replace() doesn't seem to release the memory used to do its operation. Simple example using preg_replace(): php -r 'var_dump(memory_get_usage()); $input = str_pad("", 50000, "foo"); var_dump(memory_get_usage()); $input = preg_replace(";foo;", "", $input); var_dump(memory_get_usage());' int(15216) int(65320) int(115352) Simple example using ereg_replace(): php -r 'var_dump(memory_get_usage()); $input = str_pad("", 50000, "foo"); var_dump(memory_get_usage()); $input = ereg_replace("foo", "", $input); var_dump(memory_get_usage());' int(15208) int(65312) int(15312) Maybe this is just a documentation issue, but than it should be noted. The documentation says that preg_ is faster, which it is, and the documentation somewhere mentiones a regex cache, but it doesn't say that the amount of memory grows by the size of the input sring. It's an interesting behaviour which should be considered when memory is an issue. -- Edit bug report at http://bugs.php.net/?id=35258&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=35258&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=35258&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=35258&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=35258&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=35258&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=35258&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=35258&r=needscript Try newer version: http://bugs.php.net/fix.php?id=35258&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=35258&r=support Expected behavior: http://bugs.php.net/fix.php?id=35258&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=35258&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=35258&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=35258&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35258&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=35258&r=dst IIS Stability: http://bugs.php.net/fix.php?id=35258&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=35258&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=35258&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=35258&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=35258&r=mysqlcfg

« previous php.bugs (#88358) next »