php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48368 Memory leak in array & objects
Submitted: 2009-05-23 17:24 UTC Modified: 2009-05-23 17:26 UTC
From: busia at tiscali dot it Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.0RC2 OS: Windows
Private report: No CVE-ID:
 [2009-05-23 17:24 UTC] busia at tiscali dot it
Description:
------------
When I unset an array containing object, the memory is not freed as expected. Too much memory is still used.

Reproduce code:
---------------
<?
ini_set('memory_limit','300M');
class a {
}

echo memory_get_usage()."\n";
$a=array();
for ($i=0; $i<=1000000; $i++) {
	$a[]= new a();
}
echo memory_get_usage()."\n";
unset($a);
echo memory_get_usage()."\n";
?>

Expected result:
----------------
325776
230042304
circa 325776

Actual result:
--------------
325776
230042304
33977912

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-23 17:26 UTC] jani@php.net
unset != free. The memory is freed once the process shuts down. Until 
that, it's available inside the process. This is not a leak.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Fri Apr 18 08:02:55 2014 UTC