#37929 [Fbk->Opn]: Simple multi-dimensional array uses tons of memory, gives none back to Apache2

From: Date: Thu, 20 Jul 2006 15:38:40 +0000
Subject: #37929 [Fbk->Opn]: Simple multi-dimensional array uses tons of memory, gives none back to Apache2
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-99680@lists.php.net to get a copy of this message
ID: 37929 User updated by: joe at estara dot com Reported By: joe at estara dot com -Status: Feedback +Status: Open Bug Type: Apache2 related Operating System: Linux PHP Version: 5.1.4, 4.4.0 New Comment: Mike: Please just run this below script on your machine, and then use top, hit 'M' to sort by memory and apache will be the top memory user. hit the script 10 times and your machine will start swapping to death. This appears to be apache related: if the same script is hit, it doesn't leak MORE memory, it stays at the outrageously high level it got to the first time. <?php ini_set("memory_limit", "64M"); function make_arr() { for($i=0; $i<396768; $i++) $a[sprintf("%05d",$i)] = array(0 => "PHPLEAKS923889239823", 1 => "PHPLEAK2349082349898"); return $a; } for($i=0;$i<10;$i++) $zip[$i] = make_arr(); for($i=0;$i<10;$i++) preg_match("/asdfl/", $zip[$i]["00601"][0]); ?> Previous Comments: ------------------------------------------------------------------------ [2006-07-20 15:23:40] mike@php.net Not enough information was provided for us to be able to handle this bug. Please re-read the instructions at http://bugs.php.net/how-to-report.php If you can provide more information, feel free to add it to this bug and change the status back to "Open". Thank you for your interest in PHP. Any evidence like valgrind etc? The OS releases memory when it needs it. ------------------------------------------------------------------------ [2006-07-06 18:27:57] joe at estara dot com Arrays of arrays leak memory in many PHP versions. ------------------------------------------------------------------------ [2006-07-01 00:15:27] joe at estara dot com Here, fully contained version that will make a 131M leak in 12 lines. <?php ini_set("memory_limit", "64M"); function make_arr() { for($i=0; $i<396768; $i++) $a[sprintf("%05d",$i)] = array(0 => "PHPLEAKS923889239823", 1 => "PHPLEAK2349082349898"); return $a; } for($i=0;$i<10;$i++) $zip[$i] = make_arr(); for($i=0;$i<10;$i++) preg_match("/asdfl/", $zip[$i]["00601"][0]); ?> ------------------------------------------------------------------------ [2006-07-01 00:00:26] joe at estara dot com It's 8 lines without comments. You want me to write a script to make the data file instead of just downloading it? <?php ini_set("memory_limit", "64M"); $s = file_get_contents("ziplatlong"); $z = unserialize($s); for($i=0;$i<10;$i++) $zip[$i] = unserialize($s); for($i=0;$i<10;$i++) preg_match("/asdfl/", $zip[$i]["00601"][0]); ?> ------------------------------------------------------------------------ [2006-06-30 23:17:27] tony2001@php.net Please provide _SHORT_ and complete reproduce script. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/37929 -- Edit this bug report at http://bugs.php.net/?id=37929&edit=1

« previous php.bugs (#99680) next »