Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21128 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94729 invoked by uid 1010); 9 Dec 2005 06:27:52 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 94714 invoked from network); 9 Dec 2005 06:27:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Dec 2005 06:27:52 -0000 X-Host-Fingerprint: 80.74.107.235 mail.zend.com Linux 2.5 (sometimes 2.4) (4) Received: from ([80.74.107.235:12826] helo=mail.zend.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id B3/72-14828-7E329934 for ; Fri, 09 Dec 2005 01:27:52 -0500 Received: (qmail 11830 invoked from network); 9 Dec 2005 06:01:07 -0000 Received: from localhost (HELO ANDI-NOTEBOOK.zend.com) (127.0.0.1) by localhost with SMTP; 9 Dec 2005 06:01:07 -0000 Message-ID: <7.0.0.16.2.20051208220034.02a24478@zend.com> Message-Id: <7.0.0.16.2.20051208215849.02a583b0@zend.com> X-Mailer: QUALCOMM Windows Eudora Version 7.0.0.16 Date: Thu, 08 Dec 2005 22:00:52 -0800 To: Alan Pinstein Cc: internals@lists.php.net Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed Subject: Re: [PHP-DEV] $this->this and avoiding circular references From: andi@zend.com (Andi Gutmans) Hey, re: limiting factor I don't completely disagree but then again, in most cases, it's possible to design the app in a way which resolves the problem. As to weak references, you could do weak references in PHP just by using the indirect property access. Might not be perfect but it's quite doable. Andi At 09:21 PM 12/8/2005, Alan Pinstein wrote: >>Generally speaking, if you create a circular reference (whether by >>reference or by value), then you will have a "memory leak" until >>the end of the request. This is not only true for objects (and >>circular references might be indirect) but also for arrays. > >sure, of course... > >>This is a side-effect of reference counting systems, but within the >>way PHP is used within a request/response paradigm, it shouldn't be >>a real limiting factor in real-life usage. > >Well I'd say that using a PHP-CLI script to import bulk data is a >real-life usage and this is definitely a limiting factor. Do you >disagree? > >>On the contrary, for these kind of apps, garbage collecting systems >>have potential to be significantly slower. > >Well, Cocoa solves the problem in a manner I consider quite graceful. >In 99% of situations, you don't touch memory management and things >work themselves out like in PHP. However, there is a concept of a >WEAK REFERENCE (a non-ref-counted ptr to the object) that is used >*specifically* in these cases to prevent circular references. > >With this type of system, there is no additional overhead because the >GC doesn't have to "detect" circular references and determine if the >objects are orphaned but deadlocked... instead this is a situation >left to the developer to manage. > >Now I understand that PHP isn't Obj-C and it's a higher-level >language and that's fine. > >However, my question, which still remains unanswered, is that I've >found a way that "seems" to create a weak reference and I'm simply >asking if what I am doing is condoned or just lucky (and thus a bad >idea that will probably break in the future)... > >And, if it's just lucky, then what is the solution to the problem? Am >I just SOL? Is the answer simply that if you *need* to create >circular references in PHP, then you *must* accept memory leakage? > >Alan