Am 06.08.2011 02:14, schrieb Hannes Landeholm:
Yeah I think there's a lot of misunderstandings going on with weak/soft
references and how the garbage collector works. Weak/soft references is not
some kind of solution to the cyclic reference problem. The GC takes care of
that already. You can use whatever OOP patterns with whatever reference
graphs you like Lars, the GC will free the entire structure as soon as the
cyclic collector runs after you are not referencing it anymore. You might
have become a bit confused with my last post where I explained how one could
theoretically hack together a soft reference implementation by using weak
references and some properties of cyclic collection. Also property access
performance is off-topic.

I did not misunderstand how weak/soft-references or php's new GC works.

Having a GC collect circular references is neat, but if I remember correctly, collecting them (which is why there are other, faster methods but which require more memory) is neither simple nor fast (whatever that means) so...if I can assist the GC by clearly stating that my child-objects may be collected as soon as they and their parent are not referenced from userland anymore thus not requiring the GC and thus freeing memory as soon as possible,...seems like an optimization worth thinking of. Especially if I tend to have vast structures with hundreds of objects.

In 5.2 (we can't move our project to 5.3 yet because of a BC issue) i had to manually clear those cycles before dropping the last userland reference to the tree of objects because otherwise I'd run into memory problems when processing alot of those trees.


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to