|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 12 07:00:01 2025 UTC |
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