Hi,
Got a question on proper memory management within the engine.
I have an object that stores an Array (IS_ARRAY) as a property. Inside this
property array are other objects.
So heres my memory layout for an initialized object:
Object
Property => Array (refcount = 1)
Array[0] = Object (refcount=1 if created inside Object constructor)
Array[1] = Object (refcount= >1 if passed into Object from userland)
I have a set handler so that I can set the internal array value with an
assignment.
$Object = array(1, 'string');
Results in:
Object
Property => Array (refcount = 1)
Array[0] = Object (represents an the integer 0 in this case)
Array[1] = Object (represents the string "string")
My question is, inside my set handler, I simply call zend_update_property,
during which refcount on the old Array property gets decremented to 0 and
has zval_dtor called on it.
Now the objects that were inside that array are dangling.
So here is the question.
Do I just rely on the engine itself to destroy the dangling objects in the
first array at the end of the script (which works),
or do I destruct the objects myself before replacing the property (Array)
with the new one?
Depending on the answer, what is the process to destruct an object? Just
ZVAL_DEL_REF it and let the engine GC do the rest?
Thanks
Bob Silva