On 29 March 2015 at 17:01, Roger Shepherd <rog@xxxxxxxx> wrote:
I think I understand the explanation in Stack Overflow. Essentially this says that if a one-buffered channel is used, the sending process wonât block even if the receiver is dead, and the process and channel will be garbage collected. Presumably in the implementation, a processâs memory is reclaimed only when it terminates, whereas dangling channels are garbage collected.
That is a reasonable interpretation. Go has quite straightforward memory model, using the stack as much as possible and the garbage-collected heap otherwise. Anything that goes out of scope is reclaimed either by being on the stack (and the stack pointer is moved), or by having no more references to it. This applies to both the channel and the goroutine in the specific example.
In the example, isn't it the case that with the zero-buffered channel the channel and the grouting go out of scope and should be garbage collected? So there is a bug, as the Stack Overflow post suggests.