Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54405 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73987 invoked from network); 5 Aug 2011 14:07:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Aug 2011 14:07:51 -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:49988] helo=mail1.screenlight.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 04/31-65511-539FB3E4 for ; Fri, 05 Aug 2011 10:07:50 -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; Fri, 5 Aug 2011 16:07:45 +0200 Message-ID: <4E3BF930.9030701@toolpark.com> Date: Fri, 05 Aug 2011 16:07:44 +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> <4E3A91E8.1020107@toolpark.com> <4E3ACA42.8000001@sugarcrm.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [VOTE] Weak References From: lars.schultz@toolpark.com (Lars Schultz) Am 05.08.2011 14:58, schrieb John LeSueur: > Are there other advantages I'm missing? If I may, I'll respond to your questions with 3 examples. A) Naive, straight forward approach (this will run out of memory if objects are heavy) http://pastie.org/2325252 B) Previous approach taking memory into consideration: http://pastie.org/2325317 C) Clean, memory efficient approach using SoftReferences http://pastie.org/2325254 The Problem with B) is that depending on how I use the objects, I am dropping objects from cache (to free memory) that are still in use. If I then re-add them to the cache, my singleton-pattern will be broken. NB: In the simple example I used, this is not a problem because I do not keep references to more than one object.