Re: Help on ZVAL (array) memory management
| From: | Andi Gutmans | Date: | Wed, 27 Dec 2000 05:18:02 +0000 |
| Subject: | Re: Help on ZVAL (array) memory management | ||
| References: | 1 2 3 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-42298@lists.php.net to get a copy of this message | ||
I don't know exactly what you're doing here but you should most probably use zval_ptr_dtor(&myzval); This makes sure that the zval is only destroyed if the reference count is 0; otherwise it only reduces reference count.
Andi
At 11:11 PM 12/26/00 +0100, Stig Venaas wrote:
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 -- PHP Development Mailing List <http://www.php.net/> To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net For additional commands, e-mail: php-dev-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net--- Andi Gutmans <andi@zend.com> http://www.zend.com/