Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21148 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 54107 invoked by uid 1010); 9 Dec 2005 17:54:29 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 54091 invoked from network); 9 Dec 2005 17:54:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Dec 2005 17:54:29 -0000 X-Host-Fingerprint: 194.109.193.120 unknown Linux 2.4/2.6 Received: from ([194.109.193.120:51857] helo=mx1.moulin.nl) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 87/6D-48939-2B4C9934 for ; Fri, 09 Dec 2005 12:53:54 -0500 Received: from localhost (localhost [127.0.0.1]) by mx1.moulin.nl (Postfix) with ESMTP id E0DF5189B57; Fri, 9 Dec 2005 18:53:21 +0100 (CET) Received: from mx1.moulin.nl ([127.0.0.1]) by localhost (moulin [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 01105-08; Fri, 9 Dec 2005 18:53:19 +0100 (CET) Received: from [192.168.1.16] (bspr.xs4all.nl [194.109.161.228]) by mx1.moulin.nl (Postfix) with ESMTP id F0558189B47; Fri, 9 Dec 2005 18:53:18 +0100 (CET) Message-ID: <4399C489.9040600@iamjochem.com> Date: Fri, 09 Dec 2005 18:53:13 +0100 User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Andi Gutmans Cc: Alan Pinstein , internals@lists.php.net References: <43970D54.1040206@zend.com> <63053C31-56D1-49A3-8D24-4FC41188A92A@mac.com> <7.0.0.16.2.20051208210843.059ef560@zend.com> <4399B2D7.6020500@iamjochem.com> <7.0.0.16.2.20051209090744.05acc7f0@zend.com> In-Reply-To: <7.0.0.16.2.20051209090744.05acc7f0@zend.com> X-Enigmail-Version: 0.89.5.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: amavisd-new at moulin.nl Subject: Re: [PHP-DEV] $this->this and avoiding circular references From: jochem@iamjochem.com (Jochem Maas) Andi Gutmans wrote: > Sorry about that. I think it might be a problem with the server not my > client. > If it persists please let me know. given what your work has done for me I can't consider it a problem :-) just thought it was kinda funny. regarding the actually topic of this thread I'm very interested in the concept of 'weak references' (as Apple seems to call them), what '$this->this' is all about, and whether using reference notation with object variable assignment is even allowed, whether it it makes a difference and what the future holds with regard to being able to use/create references to object 'handles'. I remember someone else asking on this list about the ability/possiblity of being able to make the distinction between object 'handles' and references to object 'handles' - I can't remember anythnig conclusive coming out of the discussion. regardless I feel that Alan did make some valid points in this area, given that the core/dev team may think that Alan's app (in this case) would be better off being refactored it might be an idea for some documentation to be created that gives an indication on how to overcome these percieved referencing problems (i.e. some strategies on how to design something that does work with in the confines of php's capabilities) for the record I have an OO based import script that imports about 13 files, one of which has 500,000 lines of data, and I see that the memory usage of my script grows and grows (upto about 100Mb) - I figure it could do it alot more efficiently, having some ammunition regarding how to tackle such an issue (in general terms) would be a great benefit - given the generic nature of the problem I believe many more developers could benefit. kind rgds, Jochem > > At 08:37 AM 12/9/2005, Jochem Maas wrote: > >> Andi - your email client seems to be leaking :-) >> >> Andi Gutmans wrote: >> >>> Hi Alan, >>> 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. >>> 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. On the contrary, for these >>> kind of apps, garbage collecting systems have potential to be >>> significantly slower. >>> Andi >>> At 08:15 PM 12/7/2005, Alan Pinstein wrote: >>> >>>> My question is closely related to the one discussed on this php-dev >>>> thread: >>>> >>>> http://thread.gmane.org/gmane.comp.php.devel/32430 >>>> >>>> Someone just sent me this link, which I didn't find myself when >>>> searching b/c the searches strip "this" from queries. >>>> >>>> Anyway, the question is related to reference counting of objects when >>>> assigned by value and by reference. It is a very important OO topic >>>> as the ability to have a non-ref-counted object "handle" is basically >>>> requisite to prevent circular reference deadlocks in OO projects. >>>> >>>> If the way I have proposed doesn't work, then what is the official >>>> way? And there *must* be one, otherwise, there is no way to avoid >>>> huge memory leaks (deferred release until end-of-script, I know, but >>>> it's a memory leak in the context of the script while it's running) >>>> with this kind of OO arrangement. >>>> >>>> In particular what confuses me is, why does, at least on PHP 5.0.4, >>>> this: >>>> >>>> $obj = &$this->this; // doesn't seem to increment the refcount of >>>> the >>>> object >>>> >>>> behaves differently from: >>>> >>>> $obj = &$this; // does seem to increment the refcount to >>>> the object >>>> >>>> References to $this should not only be valid, but are pretty much >>>> required for proper memory management in an OO environment, unless >>>> there is some other sanctioned way to get a weak reference... now I >>>> am not sure if the fact that making a & reference to an object >>>> doesn't increment the refcount is intended behavior, or an unintended >>>> side effect that may change. This is one of my major questions. >>>> >>>> Also, in regards to the thread linked above, I'd say that making & >>>> $this an error is not desirable behavior; but maybe changing the >>>> value of $this should be (ie in C terms, $this is not an lvalue). >>>> Although, in C++/Obj-C you *can* even change this/self... in fact >>>> it's common in Obj-C: >>>> >>>> - (id) init >>>> { >>>> if (self = [super init]) { /* etc */ } >>>> return self; >>>> } >>>> >>>> Of course PHP is not Obj-C, but it's OO and garbage collected in a >>>> similar way, so PHP has the same need for manipulating $this; that >>>> is, creating weak references. >>>> >>>> Alan >>>> >>>> >>>> On Dec 7, 2005, at 11:27 AM, Antony Dovgal wrote: >>>> >>>>> On 07.12.2005 18:40, Alan Pinstein wrote: >>>>> >>>>>> Hi all- >>>>> >>>>> >>>>> >>>>> >>>>> Please use php-general@lists.php.net for questions regarding >>>>> development *in* PHP. >>>>> -- >>>>> Wbr, Antony Dovgal >>>> >>>> >>>> >>>> -- >>>> PHP Internals - PHP Runtime Development Mailing List >>>> To unsubscribe, visit: http://www.php.net/unsub.php > >