From: jerome at kingofsofa dot org Operating system: linux PHP version: 5.0.4 PHP Bug Type: Performance problem Bug description: memory leak
Description: ------------ I think I have found a memory leak in php 4 and 5 depending on the size of the string concatenated to a variable a few bytes of memory are lost. See attached code. I have noticed that if you replace echo "instance $i "... by a "smaller" sentence echo "i $i " then the leak is not there. Since it has been there for a while I was wondering if this is actually an expected behavior. If so how should I do to avoid this. This is part of a script running constantly and calling some trace function that end up doing an echo. Reproduce code: --------------- for( $i = 0; $i < 100 ; $i++ ) { echo "instance $i ".memory_get_usage()."\n"; } echo "-------------------------------------------\n"; for( $i = 0; $i < 100 ; $i++ ) { echo "instance "; echo $i; echo " ".memory_get_usage()."\n"; } Expected result: ---------------- Content-type: text/html X-Powered-By: PHP/5.0.4 instance 0 40248 instance 1 40264 instance 2 40264 instance 3 40264 instance 4 40264 instance 5 40264 instance 6 40264 instance 7 40264 instance 8 40264 ... instance 99 40264 ------------------------------------------- instance 0 40264 instance 1 40280 instance 2 40280 instance 3 40280 instance 4 40280 instance 5 40280 instance 6 40280 Actual result: -------------- Content-type: text/html X-Powered-By: PHP/5.0.4 instance 0 40248 instance 1 40288 instance 2 40304 instance 3 40320 instance 4 40336 instance 5 40352 instance 6 40368 instance 7 40384 instance 8 40400 ... instance 99 41856 ------------------------------------------- instance 0 41856 instance 1 41872 instance 2 41872 instance 3 41872 instance 4 41872 instance 5 41872 instance 6 41872 -- Edit bug report at http://bugs.php.net/?id=32689&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32689&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=32689&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=32689&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=32689&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=32689&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=32689&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=32689&r=needscript Try newer version: http://bugs.php.net/fix.php?id=32689&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=32689&r=support Expected behavior: http://bugs.php.net/fix.php?id=32689&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=32689&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=32689&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=32689&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32689&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=32689&r=dst IIS Stability: http://bugs.php.net/fix.php?id=32689&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=32689&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=32689&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=32689&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=32689&r=mysqlcfg