On Wed, Jun 6, 2012 at 12:20 PM, Ivan Enderlin @ Hoa
<
[email protected]> wrote:
In addition to Gustavo's remarks, I wonder how the GC would collect a
Generator object that is not use anymore (especially with a referenced
yield). Does it fit to the current CG strategy or do we need an extra
strategy? I would notice that the “Yield by reference” section does not
exist but you have targeted it).
I added a new section which answers the question at least partially:
https://wiki.php.net/rfc/generators#closing_a_generator
Good. Thank you.
If you don't need the generator object anymore you can either
explicitly ->close() it or wait until all references to it are removed
(typically when leaving the scope of the calling function). When the
generator is closed it releases all used resources, including the
suspended execution context and the currently yielded value. Whether
or not the value is yielded by reference shouldn't make a difference.
So, yes, the current GC strategy works well for generators too :)
Ok. A very naive question: would it be interesting to make the difference between a “yield” and a “weak referenced yield values” (same concept that
https://wiki.php.net/rfc/weakreferences which is under voting phase as the RFC said).
Thank you for your clarifications.