> A parent references its childs and each child references its parent. > circular-reference nightmare...with WeakReferences I could use a > weakReference for storing the parent...so that if the parents last real > reference is discarded the childs will cleaned out as well.
that is why we added the gc in 5.3, to be able to collect the circular references, which isn't used outside of their own. as Etienne pointed out on irc, it seems that some people not really familiar how php frees the unused variables. before 5.3, we only used refcounts, if a refcount is decremented to zero the zval will be freed instantly. for example calling unset, or overwriting a variable from userland decrease the refcount for that zval. but this isn't good enough, as the refcounting couldn't spot and free the zvals, which wasn't referenced from the userland anymore, only from other unused zvals, which were also referenced by another unused zval (either two zval referencing each other, or through a "circle") this is why the gc mechanism was added in 5.3. the garbage collector runs periodically, and checks the potential zvals, and finds those zval "islands" and frees those. I hope that clears up the mess, and please correct me, if I'm wrong somewhere in the explanation. -- Ferenc Kovács @Tyr43l - http://tyrael.hu -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php