Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:54017 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9601 invoked from network); 18 Jul 2011 06:22:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jul 2011 06:22:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=lars.schultz@toolpark.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=lars.schultz@toolpark.com; 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:56984] helo=mail1.screenlight.ch) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D9/00-08769-821D32E4 for ; Mon, 18 Jul 2011 02:22:33 -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; Mon, 18 Jul 2011 08:22:28 +0200 Message-ID: <4E23D124.50104@toolpark.com> Date: Mon, 18 Jul 2011 08:22:28 +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: <4E22DDD0.20105@toolpark.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] weak references From: lars.schultz@toolpark.com (Lars Schultz) Am 17.07.2011 17:40, schrieb Hannes Landeholm: > If you are writing code that caches objects/relations and that caching has a > significant impact on memory usage, you need to care about memory > allocation/management per definition. Right. That's what I am talking about...a callback on high-memory consumption and a way to check which objects I could liberate from my cache. > So then you have to learn how OOP > memory managment works (which should be obligatory anyway if you want to > call yourself a OOP-developer IMO). I do call myself an OOP-developer but maybe I shouldn't, because I've never heard of "OOP Memory Management". Would you care to explain in private? > A common argument to why programmers > should not start with a garbage collected language is that it prevents them > from understanding memory allocation concepts. The other argument being that if you're not using a gc-language, it might prevent you from starting at all. > It would probably be simple to implement such functionality. However this > would be bad design since it would violate responsibility isolation. PHP > should expose as little internal stuff to the userland as possible - unless > there are a clear use case for it, and even then it might be a bad idea > because it could cause BC breaks in future updates. I agree with you that it's not an ideal solution. But my solution would not introduce a completely new concept to the language, but would allow advanced PHP-users to write their own custom bred solution. => "give the language a rest" > If you write code that > depend on reference counts or memory usage - you're doing something wrong. Why?...because it's not discrete? I am only taking advantage of what is already there... > The only scenario I could imagine where you could "free memory" > spontaneously on demand (when the arbitrary OOM limit is reached) - is if > that would be cached data. Exactly the case I wanted to cover. > Caching is a very complicated subject that is not > directly related to weak references. Start a separate thread about it and > present clear use cases if you have anything special in mind. I know but WeakReferences (or SoftReferences) would be a solution to this, right? It's not unrelated. > For example, I need weak references to store a table of "back references" > between objects for later reference (depends on how you use the objects). If > A references B i also need a weak reference from B to A so if B should be > replaced with a C object I need the weak reference from B to A to know that > A should be updated to point to C instead (if A still exists). This is not > related to caching. I am looking forward to the RFCs usecases...this sounds interesting.