Re: object destruction php 5.6 vs. 7.2
| From: | Nicolai Scheer | Date: | Mon, 13 Aug 2018 14:03:06 +0000 |
| Subject: | Re: object destruction php 5.6 vs. 7.2 | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-103092@lists.php.net to get a copy of this message | ||
Hi Nikita,
On Sat, 11 Aug 2018 at 11:03, Nikita Popov <nikita.ppv@gmail.com> wrote:
> On Wed, Aug 8, 2018 at 11:09 PM, Nicolai Scheer <nicolai.scheer@gmail.com>
> wrote:
>
>> [resource destructor does not get called until shutdown]
>
>
> My guess would be some kind of refcounting issue. For example
> zend_update_property will already increment the refcount of the assigned
> value itself. So if you create a value with refcount 1 and then assign it
> to an object property, you likely need to do an explicit delref. If you
> don't, then the value is leaked and your resource destructor will not run
> until shutdown.
>
>
Yes, you're absolutely right.
I switched from:
zval *rsrc = NULL;
rsrc = zend_list_insert( conn_data, le_wmqe_connection_rc );
zend_update_property( php_wmqe_connection_entry, getThis(), "connection",
sizeof( "connection" ) - 1, rsrc );
to:
zend_resource *rsrc = NULL;
rsrc = zend_register_resource( conn_data, le_wmqe_connection_rc );
add_property_resource( getThis(), "connection", rsrc );
Now the refcounting seems to be appropriate and the resource dtor gets
called on object destruction.
I guess it would be better to leave resources all alone and switch to
custom object storage for that matter...
Thanks!
Greetings
Nico