Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54353 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 75913 invoked from network); 4 Aug 2011 12:34:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Aug 2011 12:34:53 -0000 Authentication-Results: pb1.pair.com header.from=lars.schultz@toolpark.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=lars.schultz@toolpark.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain toolpark.com from 195.49.42.12 cause and error) X-PHP-List-Original-Sender: lars.schultz@toolpark.com X-Host-Fingerprint: 195.49.42.12 mail1.screenlight.ch Received: from [195.49.42.12] ([195.49.42.12:63018] helo=mail1.screenlight.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BC/2A-18399-BE19A3E4 for ; Thu, 04 Aug 2011 08:34:52 -0400 Received: from [192.168.1.112] ([192.168.1.112]) (authenticated user lars.schultz@toolpark.com) by mail1.screenlight.ch (Kerio Connect 7.0.2 patch 1) (using TLSv1/SSLv3 with cipher AES256-SHA (256 bits)) for internals@lists.php.net; Thu, 4 Aug 2011 14:34:47 +0200 Message-ID: <4E3A91E8.1020107@toolpark.com> Date: Thu, 04 Aug 2011 14:34:48 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.9) Gecko/20100915 Lightning/1.0b2 Thunderbird/3.1.4 MIME-Version: 1.0 To: internals@lists.php.net References: <4E3898B0.40809@sugarcrm.com> <4E38EC0C.9080304@lerdorf.com> <4E38FA2E.4030605@lsces.co.uk> <4E38FC67.9090200@toolpark.com> <4E39E89F.8060605@sugarcrm.com> <4E3A3643.2070305@toolpark.com> <4E3A4793.2070209@sugarcrm.com> In-Reply-To: <4E3A4793.2070209@sugarcrm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [VOTE] Weak References From: lars.schultz@toolpark.com (Lars Schultz) Am 04.08.2011 09:17, schrieb Stas Malyshev: > I'm sorry but you putting forth contradictory requirements here - you > want to keep the objects (to avoid "expensively reconstructing" them) > and you don't want to keep them (memory problems). You'll have to give > up one of these requirements. As I see, you gave up the caching > requirement and you clean up objects when memory is tight. As long as > you don't need more objects than you have memory you should be fine. As long as memory is infinite I'd be fine. It's not contradictory at all. I have to balance performance gain (keeping objects in memory) and memory usage (keeping too many objects out of memory). > You should control your code so that "somewhere else" does not keep > extra references. As well as you'd have to control you code if you use > weak refs, otherwise extra references would still keep objects alive - > or you'd have to rewrite your code and control it so that is always uses > weak refs and always checks that the ref is alive. Not true. With WeakReferences, objects would be cleaned from memory as soon as my cache-list is the only place left still referencing it and the GC is run. Even better would be SoftReferences, which would only be cleaned when there is no memory left. > Do not keep object references, keep object IDs. This would make your > code a bit more verbose and a bit slower, but weak refs would > essentially do the same anyway. This is like saying: do not use objects at all and use the DB for storage. verbosity and slowness is something I'd like to prevent. I did not mean to defend WeakReferences, I just meant to give a valid use case. Your saying that I shouldn't do it doesn't help much.