On Thu, Aug 4, 2011 at 10:37 AM, Lester Caine <les...@lsces.co.uk> wrote: > Stas Malyshev wrote: >>> >>> I am open to any suggestions how I could solve my problem without >>> WeakReference or zval-refcount (short of keeping a ref-count in >>> userland). >> >> Do not keep object references, keep object IDs. This would make your >> code a bit more verbose and a bit slower, but weak refs would >> essentially do the same anyway. > > Like you Stas I am having trouble understanding what the problem is ... > > On one 'project' I'm playing with I build a tree of genealogical references > in memory, all identified by their unique_id. If the person has already been > loaded, then it simply uses the existing reference for that element of the > tree. If there is a change to data for some reason the 'cached' record is > deleted so that it has to be re-read from the database next time it's > accessed ... if it is accessed at all. Persons are all class objects ... so > deleting is just marking the object as invalid at which point ( I hope ) the > underlying data is dropped.
if you have gc enabled, and noone else references that object, then it will be freed next time when the gc runs. what weak references are trying to solve, that if you create such a Registry, as you do, your object will always have at least one reference (your Registry holds them), so gc won't collect those. with weak references, you can lazy load your Person records as you do, but every People record which only referenced through Weakrefs will be garbage collected on the next gc run. collecting the garbage will happen if the gc root buffer is full, or if you manually call gc_collect_cycles. http://www.php.net/manual/en/features.gc.collecting-cycles.php -- Ferenc Kovács @Tyr43l - http://tyrael.hu -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php