#35258 [Fbk->Bgs]: preg_replace() doesn't release memory

From: Date: Thu, 17 Nov 2005 12:59:30 +0000
Subject: #35258 [Fbk->Bgs]: preg_replace() doesn't release memory
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-88378@lists.php.net to get a copy of this message
ID: 35258 Updated by: tony2001@php.net Reported By: mfischer@php.net -Status: Feedback +Status: Bogus Bug Type: PCRE related Operating System: Linux PHP Version: 4.4.1 New Comment: Memory usage doesn't depend on the length of the data. Try this code: <?php var_dump(memory_get_usage()); $input = str_pad("", 50000, "foo"); var_dump(memory_get_usage()); $input = preg_replace(";foo;", "", $input); unset($input); // <------------ !! var_dump(memory_get_usage()); ?> Previous Comments: ------------------------------------------------------------------------ [2005-11-17 13:55:54] sniper@php.net Please try using this CVS snapshot: http://snaps.php.net/php5-latest.tar.gz For Windows: http://snaps.php.net/win32/php5-win32-latest.zip ------------------------------------------------------------------------ [2005-11-17 12:22:25] mfischer@php.net 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 this bug report at http://bugs.php.net/?id=35258&edit=1

« previous php.bugs (#88378) next »