zend_object destructor issue

From: Date: Thu, 11 Sep 2008 11:30:50 +0000
Subject: zend_object destructor issue
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-5747@lists.php.net to get a copy of this message
Hi! I have interesting case with objects constructors and destructors. Every zend_object has underlying GObject implemented similiar to php-gtk extension. Code example: $i = 1; while(true) { $obj = new my_class(); $i++; if($i % 1000 == 0) { echo(" $i / ".memory_get_usage() . "\n"); } if($i == 10000) exit(); } In this example memory_get_usage isn't increased. I would even say, it's constant. Object's constructor and destructor are both invoked. Destructor is almost this: zend_object_std_dtor g_object_unref ( it doesn't affect memory_limit anyway ) Now, problem appears when one of 'my_class' property is of object type. Not pure PHP object, but the one with GObject implemented as underlying storage. When I run this example code, memory grows and grows as long as it reaches memory limit. I thought that I should implement additional destructor for all properties of object type. HashPosition iterator; zval **zvalue; HashTable *props = zo->properties; zend_hash_internal_pointer_reset_ex(props, &iterator); while (zend_hash_get_current_data_ex(props, (void **)&zvalue, &iterator) == SUCCESS) { if(Z_TYPE_PP(zvalue) == IS_OBJECT) { } zend_hash_move_forward_ex(props, &iterator); } But what exactly should be invoked for property of object type? zend_objects_free_object_storage ? zend_objects_destroy_object ? my_destructor ( which in fact calls only zend_object_std_dtor ) ? zend_object_std_dtor ? zval_dtor ? efree? Properties of object type are correctly destroyed ( with proper memory freed ) at request end. But this is not a point. I need to free memory on demand. When I try with some API functions above I can decrease memory usage about 30%. Not more. What is the proper, zend way to do this? Piotras

« previous php.pecl.dev (#5747) next »