|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-12-07 07:13 UTC] lstrojny@php.net
[2008-12-07 13:18 UTC] o_O_Tync at mail dot ru
[2008-12-07 15:33 UTC] scottmac@php.net
[2008-12-07 15:39 UTC] scottmac@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 24 01:00:02 2025 UTC |
Description: ------------ I've come across a memory leak: garbage collector failes to free memory occupied by linked objects, such as: $obj1->pair = $obj2; $obj2->pair = $obj1; Below goes the problematic piece of code: over many iterations - it occupies a lot of memory. If we comment 'line1' or 'line2' or both - memory is okay (48 Kb), but cross-linking reveals a bug (839 Kb) despite of explicit unsetting. The commented 'this helps' line solves the problem. Tested under WinXP, and FreeBSD 6.1 using the latest PHP 5.2.7 Reproduce code: --------------- <?php class Paired { /** Paired object * @var Paired */ public $pair; } for ($i=0;$i<2000;$i++) { $obj1 = new Paired; $obj2 = new Paired; $obj1->pair = $obj2; // 'line1' $obj2->pair = $obj1; // 'line2' // $obj1->pair = null; $obj2->pair = null; // this helps unset($obj1); unset($obj2); // Explicitly } print 'Mem: '.floor(memory_get_usage()/1024).' Kb'; ?> Expected result: ---------------- Mem: 48 Kb Actual result: -------------- Mem: 839 Kb