Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54490 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 823 invoked from network); 9 Aug 2011 12:22:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2011 12:22:54 -0000 Authentication-Results: pb1.pair.com header.from=arvids.godjuks@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=arvids.godjuks@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.170 as permitted sender) X-PHP-List-Original-Sender: arvids.godjuks@gmail.com X-Host-Fingerprint: 209.85.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:42590] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C6/50-30512-D96214E4 for ; Tue, 09 Aug 2011 08:22:53 -0400 Received: by vxh24 with SMTP id 24so3785243vxh.29 for ; Tue, 09 Aug 2011 05:22:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=Ehi2Hi6hhovt4rbiqldruoTYltd8aH+0EYX29GOEW5g=; b=W+DPWdPRV43ItFamWNI6ICwwKgLxfPEpjoNWkWGTTUlDhHfqanV+aSycAp3yWsyshE tKQcl1/v0Yt6Z8JHkTE3L/RstqUIFeI0kqNIQP8YlEPOC/TEmA6vX4AVZqlRKYxGyuT0 VlqiNEGDfyJbtzWaOpE5+1S+HONZNbduunISw= MIME-Version: 1.0 Received: by 10.52.32.196 with SMTP id l4mr1180944vdi.16.1312892571278; Tue, 09 Aug 2011 05:22:51 -0700 (PDT) Received: by 10.52.185.41 with HTTP; Tue, 9 Aug 2011 05:22:51 -0700 (PDT) In-Reply-To: <4E3D073A.9050709@toolpark.com> References: <4E39E89F.8060605@sugarcrm.com> <4E3A3643.2070305@toolpark.com> <4E3A4793.2070209@sugarcrm.com> <4E3A91E8.1020107@toolpark.com> <4E3ACA42.8000001@sugarcrm.com> <4E3BF930.9030701@toolpark.com> <4E3C5EDE.3030401@toolpark.com> <4E3D073A.9050709@toolpark.com> Date: Tue, 9 Aug 2011 15:22:51 +0300 Message-ID: To: internals@lists.php.net Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [VOTE] Weak References From: arvids.godjuks@gmail.com (Arvids Godjuks) I have mixed feelings about this proposal - from one point it's quite neat - ability to mark circular references for the memory manager so it can free them sounds very delicious, especially for some cases. I had run into my own bunch of problems with memory in PHP in the past and right now I'm running a daemon written in PHP in production on 5.3.6. Careful construction and knowledge that circular references actually do harm I did add safeguards that actually clean up the objects in recursive manner (and objects have internal flags that cleanup has been initiated - that way I make sure I cleanup the same object only once). That sort of planing at the design stage makes it far more friendly with memory, so it doesn't mean that PHP should have soft references. My opinion is that if this can be done without using significant resources and will not have major issues while implementing - it can be added, otherwise just skip it - better off fixing bugs and optimizing :) 2011/8/6 Lars Schultz : > Am 06.08.2011 02:14, schrieb Hannes Landeholm: >> >> Yeah I think there's a lot of misunderstandings going on with weak/soft >> references and how the garbage collector works. Weak/soft references is >> not >> some kind of solution to the cyclic reference problem. The GC takes care >> of >> that already. You can use whatever OOP patterns with whatever reference >> graphs you like Lars, the GC will free the entire structure as soon as the >> cyclic collector runs after you are not referencing it anymore. You might >> have become a bit confused with my last post where I explained how one >> could >> theoretically hack together a soft reference implementation by using weak >> references and some properties of cyclic collection. Also property access >> performance is off-topic. > > I did not misunderstand how weak/soft-references or php's new GC works. > > Having a GC collect circular references is neat, but if I remember > correctly, collecting them (which is why there are other, faster methods but > which require more memory) is neither simple nor fast (whatever that means) > so...if I can assist the GC by clearly stating that my child-objects may be > collected as soon as they and their parent are not referenced from userland > anymore thus not requiring the GC and thus freeing memory as soon as > possible,...seems like an optimization worth thinking of. Especially if I > tend to have vast structures with hundreds of objects. > > In 5.2 (we can't move our project to 5.3 yet because of a BC issue) i had to > manually clear those cycles before dropping the last userland reference to > the tree of objects because otherwise I'd run into memory problems when > processing alot of those trees. > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >