Electronics & Programming


Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » [PHP-DEV] Good memory management [RSS Feed]

#1 Nov. 10, 2005 03:40:44

Bob S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] Good memory management


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:


Property => Array (refcount = 1)

Array = Object (refcount=1 if created inside Object constructor)

Array = 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

$Object = array(1, 'string');

Results in:


Property => Array (refcount = 1)

Array = Object (represents an the integer 0 in this case)

Array = 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?


Bob Silva


  • Root
  • » PHP
  • » [PHP-DEV] Good memory management [RSS Feed]

Board footer

Moderator control

Enjoy the 24th of April

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support