On Thu, Aug 4, 2011 at 12:17 PM, Lester Caine <les...@lsces.co.uk> wrote: > I'm still trying to get my head around this 'Weak Reference' thing, but > since I'm still working to be compatible with PHP5.2 then I've not taken > much notice of this 'garbage collection' stuff. So this may be where I am > missing something? I manage what material I need using a list of numbers, > and create objects as and when they are required, pulling the detail from > the database. There is a limit on the amount of memory available, so in the > past I got 'out of memory', now I just say 'some detail not available'. If > I'm out of space, then I reuse an existing object that is 'invalid', but to > simplify things then much of the time I don't ACTUALLY need the full record, > and simply build the page via the one object which is sequentially loaded > ... slower, but memory efficient. Never do 'SELECT * FROM', always specify > just the fields you need at that time. > > So it looks like the question I should be asking is "How do you 'drop' an > object?" I think my take on this 'Weak Reference' stuff is that it does not > actually 'create' the object? But I am creating the object because I need to > use it, not because I may need it later? I'll get the database server to do > any heavy processing ... and that may well be a different machine ... I just > want the results. So I try to avoid pulling unnecessary data into the PHP > side - I can only put so much on a client page. >
if you unset a variable, the zval's refcount for that variable will be decreased by one. if the refcount reach zero, the zval will be freed. http://www.php.net/manual/en/features.gc.refcounting-basics.php this was also before 5.3 the new feature in 5.3 however you can fix the memory leaks that happened because of the circular references: http://www.php.net/manual/en/features.gc.collecting-cycles.php a simple example for circular reference is basically when you have two zval, they both reference each other, so their refcount is one, so they cannot be freed, but they should been. this was addressed in 5.3, now the gc collector will traverse the zvals and find such "islands" and free them. so to address your question: if you unset your variables you can reclaim memory, but there could be edge cases, when you will memory leak before version 5.3. -- Ferenc Kovács @Tyr43l - http://tyrael.hu -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php