Re: [VOTE] Weak References

From: Date: Sat, 06 Aug 2011 09:19:54 +0000
Subject: Re: [VOTE] Weak References
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
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.

Thread (69 messages)

« previous php.internals (#54420) next »