<div dir="auto">Yes, I understand that now that's not easy to do in Java. I just don't think it's all that exotic, and certainly not a bug. After all, we've all written at least one iterator when we did a coding interview.<div dir="auto"><br></div><div dir="auto">There is 1:1 correspondence between the iterators and the generators. So if we can GC the iterators without special dance, we should be able to do that for the generators. You could see an iterator as an explicit declaration that you are not going to use any features that rely on there being a finally - no unlocking, no resource management outside of what a finalizer can achieve, no peer to coordinate with, etc. Likewise an explicit declaration by an engineer that this here piece of code entering a wait is perfectly fine to GC, doesn't seem all that different.</div><div dir="auto"><br></div><div dir="auto">Yes, in general there are thread semantics, try-finally, reference loops and other obstacles - but we don't need to solve a general case, just the one that is in 1:1 correspondence with the iterators.</div><div dir="auto"><br></div><div dir="auto">I understand that there may be safe ways to implement the same with the existing mechanisms - like, the user of the generator might wrap the interaction in a try-with-resource, and that way control the lifecycle explicitly. </div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, 13 Jan 2026, 08:00 Alan Bateman, <<a href="mailto:alan.bateman@oracle.com">alan.bateman@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
On 13/01/2026 06:42, Alex Otenko wrote:<br>
><br>
> I think there are plenty of designs with generators, iterators and <br>
> async where non-termination is not a bug.<br>
<br>
That is true is some other languages/runtimes. If Java were to add <br>
generators or some other exotic control flow in the future then there <br>
would be more spooky issues to work through, some of which overlap with <br>
the spooky issues that have come up in the discussion here.<br>
<br>
-Alan<br>
</blockquote></div>