Re: [PHP-DEV] Help on ZVAL (array) memory management From: Stig Venaas (Stig.Venaas <email protected>)
Date: 12/26/00

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 <email protected>
For additional commands, e-mail: php-dev-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>