Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54334 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 11250 invoked from network); 4 Aug 2011 07:17:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Aug 2011 07:17:45 -0000 Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 67.192.241.123 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.123 smtp123.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.123] ([67.192.241.123:48854] helo=smtp123.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 00/82-30993-7974A3E4 for ; Thu, 04 Aug 2011 03:17:44 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp22.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id B16DB170867; Thu, 4 Aug 2011 03:17:40 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp22.relay.dfw1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 52BC717084D; Thu, 4 Aug 2011 03:17:40 -0400 (EDT) Message-ID: <4E3A4793.2070209@sugarcrm.com> Date: Thu, 04 Aug 2011 00:17:39 -0700 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: Lars Schultz CC: "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> In-Reply-To: <4E3A3643.2070305@toolpark.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [VOTE] Weak References From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! On 8/3/11 11:03 PM, Lars Schultz wrote: > (from the cache). This works very well and keeps me from expensively > reconstructing objects from the DB. What it does not work well with is > Garbage collection, since the an object will always be referenced at > least once (by the cache). The longer a script is running, the higher 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. > objects from the cache, always running the risk that my singleton is > suddenly not so single anymore, because a discarded object was still > referenced somewhere else. 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. > I am open to any suggestions how I could solve my problem without > WeakReference or zval-refcount (short of keeping a ref-count in userland). 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. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227