From: jimmycnw at gmail dot com Operating system: Linux PHP version: 5.2.6 PHP Bug Type: Performance problem Bug description: Memory leak in unserialize of nested arrays
Description: ------------ The code is attached. Try executing 'SAVING' first. It will create a file 'temp.txt' approximately 450Kb in size. Then execute 'LOADING'. You will see, that over 3.5Mb (!!) of memory used in unserialize() function, while there are just 450Kb of data. Is it a bug in PHP? Any suggestions on how to fix it? (When I do the same with string, not array, everything works fine. The problem appears only when I use nested arrays) Reproduce code: --------------- define ('FILENAME', 'temp.txt'); define ('SIZE', 10 * 1024); // SAVING $array = array (); for ($i = 0; $i<SIZE; $i++) $array[] = array (uniqid ($i) => array ()); $data = serialize ($array); file_put_contents (FILENAME, $data); // LOADING $before = memory_get_usage (); $array = unserialize (file_get_contents (FILENAME)); $after = memory_get_usage (); echo 'Memory used: '.($after-$before).' bytes, while size of data: '.strlen (serialize ($array)); Expected result: ---------------- Memory used should be around 450Kb, while I see 3.5Mb. Actual result: -------------- Memory used: 3.5Mb -- Edit bug report at http://bugs.php.net/?id=46018&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46018&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46018&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46018&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46018&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=46018&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46018&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46018&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46018&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46018&r=support Expected behavior: http://bugs.php.net/fix.php?id=46018&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46018&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46018&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46018&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46018&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46018&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46018&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46018&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46018&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46018&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46018&r=mysqlcfg