php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60983 Memory is not properly freed
Submitted: 2012-02-06 00:43 UTC Modified: 2012-02-07 02:54 UTC
From: developerguy2008 at yahoo dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.4.0RC7 OS: all
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: developerguy2008 at yahoo dot com
New email:
PHP Version: OS:

 

 [2012-02-06 00:43 UTC] developerguy2008 at yahoo dot com
Description:
------------
Memory is not being freed properly. In a short loop several megabytes are lost that should not be lost. Attached is a test script to demonstrate what I mean.

Test script:
---------------
$mem1 = memory_get_usage(true);
echo "MEM1: " . $mem1 . "\n";
class A {
	public $class;
}

$c1 = $c2 = null;
for ($i = 0; $i < 20000; $i++) {
	$c1 = new A();
	$c2 = new A();
	$c1->class = array($c1, $c2);
	$c2->class = array($c1, $c2);
}
unset($c1); unset($c2);

gc_collect_cycles();
$mem2 = memory_get_usage(true);
echo "MEM2: " . $mem2 . "\n";
echo "DIFF: " . ($mem2 - $mem1) . "\n";

Expected result:
----------------
I expect the memory difference to be 0. In this case it is several megabytes.

Actual result:
--------------
MEM1: 4980736
MEM2: 7340032
DIFF: 2359296

The DIFF should be 0.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-06 07:46 UTC] laruence@php.net
-Status: Open +Status: Not a bug
 [2012-02-06 07:46 UTC] laruence@php.net
the reason for there is mem diff is that, the EG(objects_store) could only be 
grow  but could not be shrunk. 

if you tweak your test into:
$mem1 = memory_get_usage(true);
echo "MEM1: " . $mem1 . "\n";
class A {
	public $class;
}

$c1 = $c2 = null;
for ($i = 0; $i < 20000; $i++) {
	$c1 = new A();
	$c2 = new A();
	$c1->class = array($c1, $c2);
	$c2->class = array($c1, $c2);
       
        gc_collect_cycles();

}
unset($c1); unset($c2);

$mem2 = memory_get_usage(true);
echo "MEM2: " . $mem2 . "\n";
echo "DIFF: " . ($mem2 - $mem1) . "\n";

you may understand my point
 [2012-02-06 17:16 UTC] DeveloperGuy2008 at yahoo dot com
Do you know any references where I may read about the object_store? Is there a to shrink it (like a compile time flag) when it is does not need to be large?

It seems like the ideal result would be to shrink the object store. In this example it is only a few megabytes but in other cases it could be several hundred megabytes that essentially lost forever (at least to other processes).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 21:01:33 2025 UTC