Bug #66939 [NEW]: memory leak when assigning big arrays of objects to variable while iterating

From: Date: Fri, 21 Mar 2014 20:07:54 +0000
Subject: Bug #66939 [NEW]: memory leak when assigning big arrays of objects to variable while iterating
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184851@lists.php.net to get a copy of this message
From: anton dot ponadiozin at gmail dot com Operating system: Debian Wheezy PHP version: 5.4.26 Package: Performance problem Bug Type: Bug Bug description:memory leak when assigning big arrays of objects to variable while iterating Description: ------------ Memory consumption increases while assigning big (>1000) arrays of object to same variable. In my case i was generating some financial report for long period of time. Database were returning array of result objects. Longer period i was selecting significantly more memory (than it should be) was used. ➜ ~ uname -a Linux ap 3.12-0.bpo.1-amd64 #1 SMP Debian 3.12.9-1~bpo70+1 (2014-02-07) x86_64 GNU/Linux ➜ ~ php -v PHP 5.4.4-14+deb7u8 (cli) (built: Feb 17 2014 09:18:47) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies with Xdebug v2.2.1, Copyright (c) 2002-2012, by Derick Rethans Test script: --------------- <?php function get_objects() { $array = array(); for ($i=0; $i<5000; $i++) { $object = new stdClass(); $object->a = rand(); $object->b = rand(); $object->c = rand(); $object->d = rand(); $object->e = rand(); $array[] = $object; } return $array; } $results = array(); for ($i=0; $i<30; $i++) { $results = get_objects(); echo memory_get_usage(true) . "\n"; // assigning empty array fixes the problem // $results = array(); } Expected result: ---------------- ➜ ~ php bug.php 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 6291456 Actual result: -------------- ➜ ~ php bug.php 6291456 7340032 7340032 7602176 7602176 7864320 7864320 8126464 8126464 8388608 8388608 8650752 8650752 8912896 8912896 9175040 9175040 9437184 9437184 9699328 9699328 9961472 9961472 10223616 10223616 10485760 10485760 10747904 10747904 11010048 -- Edit bug report at https://bugs.php.net/bug.php?id=66939&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66939&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66939&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66939&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=66939&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=66939&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=66939&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=66939&r=needscript Try newer version: https://bugs.php.net/fix.php?id=66939&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=66939&r=support Expected behavior: https://bugs.php.net/fix.php?id=66939&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=66939&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=66939&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=66939&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66939&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=66939&r=dst IIS Stability: https://bugs.php.net/fix.php?id=66939&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=66939&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=66939&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=66939&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=66939&r=mysqlcfg

« previous php.bugs (#184851) next »