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

From: Date: Fri, 15 Aug 2014 04:29:25 +0000
Subject: Bug #66939 [Com]: memory leak when assigning big arrays of objects to variable while iterating
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-187136@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66939&edit=1 ID: 66939 Comment by: klakurka at gmail dot com Reported by: anton dot ponadiozin at gmail dot com Summary: memory leak when assigning big arrays of objects to variable while iterating Status: Open Type: Bug Package: Performance problem Operating System: Debian Wheezy PHP Version: 5.4.26 Block user comment: N Private report: N New Comment: Issue is still present in PHP 5.5.15. Usage continues to rise by an ever-increasing amount -- this is not linear. Code Snippet: --- foreach ($things as $thing) { if(date('g:iA', $thing['intTimeStamp']) == '8:00AM') { echo 'Starting new day... ', date('F jS, Y', $thing['item']), '<br />'; echo "Total: " . memory_get_peak_usage()/1024/1024 . "MB<br />"; } ob_flush(); flush(); $startMemory = memory_get_peak_usage()/1024/1024; $largeDataSet = $api->getLargeDataSet($thing['something']); echo 'Memory Delta: ' . (memory_get_peak_usage()/1024/1024 - $startMemory) . '<br />'; $dataProcessor->processData($thing['something'], $largeDataSet); } --- Linux server.localdomain 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux PHP 5.5.15 (cli) (built: Jul 24 2014 10:25:49) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies Previous Comments: ------------------------------------------------------------------------ [2014-03-21 20:14:46] anton dot ponadiozin at gmail dot com Just upgraded to latest PHP, the problem persists ➜ ~ php -v PHP 5.4.26-1~dotdeb.1 (cli) (built: Mar 7 2014 09:42:03) ------------------------------------------------------------------------ [2014-03-21 20:07:53] anton dot ponadiozin at gmail dot com 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 this bug report at https://bugs.php.net/bug.php?id=66939&edit=1

« previous php.bugs (#187136) next »