Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:6751 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78149 invoked by uid 1010); 3 Jan 2004 00:09:47 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 78124 invoked from network); 3 Jan 2004 00:09:46 -0000 Received: from unknown (HELO mrout2.yahoo.com) (216.145.54.172) by pb1.pair.com with SMTP; 3 Jan 2004 00:09:46 -0000 Received: from bourbon.corp.yahoo.com (bourbon.corp.yahoo.com [216.145.53.135]) by mrout2.yahoo.com (8.12.10/8.12.10/y.out) with ESMTP id i0309L26006707 for ; Fri, 2 Jan 2004 16:09:21 -0800 (PST) Received: (from andrei@localhost) by bourbon.corp.yahoo.com (8.12.9/8.11.1) id i0309LSV003738 for internals@lists.php.net; Fri, 2 Jan 2004 16:09:21 -0800 (PST) (envelope-from andrei) Date: Fri, 2 Jan 2004 16:09:21 -0800 To: internals@lists.php.net Message-ID: <20040103000921.GA3712@gravitonic.com> References: <20040103000120.GA23760@csh.rit.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20040103000120.GA23760@csh.rit.edu> User-Agent: Mutt/1.4.1i Subject: Re: [PHP-DEV] Custom object creation and reference counts From: andrei@gravitonic.com (Andrei Zmievski) On Fri, 02 Jan 2004, Jon Parise wrote: > It looks like this code from zend_execute.c is responsible for the > added reference: > > if (PZVAL_IS_REF(value) && value->refcount > 0) { > ALLOC_ZVAL(variable_ptr); > *variable_ptr_ptr = variable_ptr; > *variable_ptr = *value; > zval_copy_ctor(variable_ptr); > variable_ptr->refcount=1; > break; > } > > In my case, 'value' is a reference (PZVAL_IS_REF(value) == 1), and in > the case of the native PHP object, it isn't. zval_copy_ctor() calls > zend_objects_store_add_ref(), which increments the store object's > reference count. > > Two questions: > > Why is my object being treated as a reference while the native PHP > object is not? I guess that is a question for you really: are you doing anything special to make your object a reference? I've used the new object model for PHP-GTK and my objects were not treated as references. > 'variable_ptr->refcount=1;' resets the reference count of the > variable's zval to 1, but the underlying _store_object's reference > count is still incremented. What will ever reclaim that reference on > the _store_object? zval_dtor() will. It calls del_ref on the underlying object. - Andrei