Re: Help on ZVAL (array) memory management

From: Date: Tue, 26 Dec 2000 22:11:09 +0000
Subject: Re: Help on ZVAL (array) memory management
References: 1 2  Groups: php.dev 
Request: Send a blank email to php-dev+get-42291@lists.php.net to get a copy of this message
On Tue, Dec 26, 2000 at 03:49:01PM -0500, Huajie Liu wrote: > Thanks Stig, > > What I am trying to do is to convert a C tree structure to > php array (hashtable) so that I can use this data structure > from my php scripts. I tried to use zval_dtor() but it seems > not to free the whole structure contained by zval, including > the hashtable in hashtable. > > In the my code snippet, if I zval_dtor(myzval), will 'zarray' > get freed too? Yes I think so. array_init(myzval) will set myzval->value.ht->pDestructor to ZVAL_PTR_DTOR. When you later do zval_dtor(myzval), it will do zend_hash_destroy(myzval->value.ht) which will then do ZVAL_PTR_DTOR(q->pData) for each element in the hash (q). Each pData refers to a zval, and it will reduce the refcount of the zval, and if it becomes 0, it will do zval_dtor on it. So in your case, the effect should be that it calls zval_dtor(zarray) unless the refcount >1. If I'm wrong, someone that knows this better will hopefully correct me. A debugger should be able to help you a lot, just trace step by step what happens when you try to free myzval. Stig

« previous php.dev (#42291) next »