From: kris dot public at kauper dot net Operating system: Fedora Core 2 PHP version: 5CVS-2004-12-26 (dev) PHP Bug Type: *General Issues Bug description: object instantiation/destruction memory leak
Description: ------------ While trying to track down a memory leak in my app, I came across this behaviour: Instantiating an object of a class that contains 9 or more class variables, and then destroying that object, leaves 64 bytes of unreclaimed memory. Performing the same test with a class that contains 8 or fewer class variables does not result in the same memory leak. I've tried the supplied test script with PHP 4.3.8/9/10 and the latest CVS version of PHP5, with the same results for each. In each case, I compiled PHP using: ./configure --enable-memory-limit Reproduce code: --------------- <?php // simple class having 9 class variables class ClassWith9Vars { var $a1 = NULL; var $a2 = NULL; var $a3 = NULL; var $a4 = NULL; var $a5 = NULL; var $a6 = NULL; var $a7 = NULL; var $a8 = NULL; var $a9 = NULL; } // simple class having 8 class variables class ClassWith8Vars { var $a1 = NULL; var $a2 = NULL; var $a3 = NULL; var $a4 = NULL; var $a5 = NULL; var $a6 = NULL; var $a7 = NULL; var $a8 = NULL; } echo ("Starting test using ClassWith9Vars\n"); $m1 = memory_get_usage(); for ($i = 0; $i < 10; $i++) { $test =& new ClassWith9Vars(); unset($test); $m2 = memory_get_usage(); echo ("leak = " . ($m2 - $m1) . "\n"); $m1 = $m2; } echo ("Starting test using ClassWith8Vars\n"); $m1 = memory_get_usage(); for ($i = 0; $i < 10; $i++) { $test =& new ClassWith8Vars(); unset($test); $m2 = memory_get_usage(); echo ("leak = " . ($m2 - $m1) . "\n"); $m1 = $m2; } ?> Expected result: ---------------- Starting test using ClassWith9Vars leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 Starting test using ClassWith8Vars leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 Actual result: -------------- Starting test using ClassWith9Vars leak = 608 leak = 88 leak = 64 leak = 64 leak = 64 leak = 64 leak = 64 leak = 64 leak = 64 leak = 64 Starting test using ClassWith8Vars leak = 32 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 leak = 0 -- Edit bug report at http://bugs.php.net/?id=31297&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31297&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31297&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31297&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=31297&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=31297&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=31297&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=31297&r=needscript Try newer version: http://bugs.php.net/fix.php?id=31297&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=31297&r=support Expected behavior: http://bugs.php.net/fix.php?id=31297&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=31297&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=31297&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=31297&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31297&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=31297&r=dst IIS Stability: http://bugs.php.net/fix.php?id=31297&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=31297&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=31297&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=31297&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=31297&r=mysqlcfg