php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44665 Memory leak in array_push operation
Submitted: 2008-04-07 22:35 UTC Modified: 2008-04-08 10:57 UTC
From: sasha at integrate dot ru Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.2.5 OS: Linux
Private report: No CVE-ID: None
 [2008-04-07 22:35 UTC] sasha at integrate dot ru
Description:
------------
Sorry for my english

php with curl, dbase, dom, gd2, mbstring,pgsql, simplexml,soap,sockets 

It running under eAccelerator, but when I turn it off, the result is just the same.

actually we use only pgsql. we get request (rather big - more than 3000 rows in result) making array of objects and then trying to convert each object into html string. converted string (each about 2 Kb length) have been pushed into array
very soon memory usage growing to 64 Mb and script is crushed
This problem is solved by method refact

	protected function _refact($arr)
	{
	$myarr=array();
	while(!empty($arr)) $myarr[]=array_shift($arr);
	
	return ($myarr);
	}

I call this function after 75, 150, 300 etc iterations, but calling this function reduce performance. Is that behaviour (I mean memory usage growing) normal?  

Reproduce code:
---------------
Normal script (crushed)

http://ver.web.integrate.ru/test1.php

Cheated script (with refact method)
http://ver.web.integrate.ru/test1.php


Each script reports tht Init memory (Memory at the begin), how much objects it proceeds (Now showing), iteration counter (Cicling iteration), current memry usage (current memory usage) and length of string we pushed into array (string_length). 

Cheated script (in red hrs) show also the length of array we throw to refact method


Expected result:
----------------
I guess that the memory usage won't grow while running this script because the array of objects poped every turn, and the volume of each element of this array more than the volume of elements of the result array 

Actual result:
--------------
U can see it on url I submit

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-04-08 00:13 UTC] sasha at integrate dot ru
sorry - wrong second link
the right link is 
http://ver.web.integrate.ru/test2.php
 [2008-04-08 10:57 UTC] jani@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 08 03:01:32 2025 UTC