Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43266 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17601 invoked from network); 6 Mar 2009 07:16:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Mar 2009 07:16:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain zend.com designates 212.25.124.163 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 212.25.124.163 il-gw1.zend.com Windows 2000 SP4, XP SP1 Received: from [212.25.124.163] ([212.25.124.163:14297] helo=il-gw1.zend.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A7/2C-42068-BDDC0B94 for ; Fri, 06 Mar 2009 02:16:45 -0500 Received: from ws.home ([10.1.10.2]) by il-gw1.zend.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 6 Mar 2009 09:18:03 +0200 Message-ID: <49B0CDD6.5050205@zend.com> Date: Fri, 06 Mar 2009 10:16:38 +0300 User-Agent: Thunderbird 2.0.0.19 (X11/20090105) MIME-Version: 1.0 To: Igor Feghali CC: PHP Developers Mailing List References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 06 Mar 2009 07:18:03.0724 (UTC) FILETIME=[B06940C0:01C99E2B] Subject: Re: [PHP-DEV] Memory Leaks with Objects (no circular reference) From: dmitry@zend.com (Dmitry Stogov) Hi Igor, It's definitely not a memory leak. The memory manager in php-5.2 was changed so it behaves little bit different. BTW: both 5.1 and 5.2 use some caches of the chunks with most useful sizes. They allow to eliminate annecessury free()/malloc() calls and speedup the whole system. memory_get_usage() returns allocated memory including these caches, so you can think that memory lost however it's just preallocated and ready for next emalloc()s. Thanks. Dmitry. Igor Feghali wrote: > Hi, > > I am facing some memory leaks with php 5.1.6 that has been fixed in > 5.2.0. So I suppose the fix should be somewhere between those > versions, but I couldn't find exactly which line in the NEWS file is > that. > > > class foo > { > var $a1; > var $a2; > var $a3; > var $a4; > var $a5; > var $a6; > var $a7; > var $a8; > var $a9; > } > > class bar > { > var $a1; > var $a2; > var $a3; > var $a4; > var $a5; > var $a6; > var $a7; > var $a8; > } > > echo "--- 9 ---\n"; > for ($i = 0; $i < 5; $i++){ > $u =& new foo(); > unset($u); > echo memory_get_usage()."\n"; > } > > echo "--- 8 ---\n"; > for ($i = 0; $i < 5; $i++){ > $u =& new bar(); > unset($u); > echo memory_get_usage()."\n"; > } > > ?> > > Output for 5.1.6: > --- 9 --- > 44712 > 44784 > 44848 > 44912 > 44976 > --- 8 --- > 45008 > 45008 > 45008 > 45008 > 45008 > > Conclusion: memory consumption keeps constant for the class with 8 > properties. unset() doesnt frees all the memory up for the class with > 9 properties. > > Output for 5.2.0: > --- 9 --- > 66784 > 66828 > 66828 > 66828 > 66828 > --- 8 --- > 66896 > 66896 > 66896 > 66896 > 66896 > > Conclusion: memory consumption constant along the whole code, as expected. > > I have seen that reported many times in the bugs system, but in all > the cases it ended up being something related to circular references > which is not the case here. Some people also reported that replacing > "unset($obj)" with "$obj = null" would help but I tried it and the > problem remains. > > Any help on how to workaround that in userland would be very > appreciated. Surely upgrading will fix that, but I am trying to keep > compatibility with prior versions as much as possible. > > Best, > ~IF. >