I think not closing the channel has the side effect, of making it easier to leak goroutines. If your memory is growing, its likely that there is still a receiver who didn't realize there is nothing more to receive. That is one thing closing a channel can do and oftentimes does, i.e. when ranging over channels.
So when not closing channels, one needs another way to signal that all references to that channel should be released, so the garbage collector can collect it. I never thought about it much but it makes sense that closing a channel, does not free resources. Because you can still receive remaining values from a closed channel and the zero value afterwards. So it must be garbage collected, not matter what. I also missed the earlier posts by Robert and Jason, who already pointed this out. I really wish someone had told me this earlier. Although it has an extra disclaimer on the tour. So, my bad. https://go.dev/tour/concurrency/4 > Another note: Channels aren't like files; you don't usually need to > close them. Closing is only necessary when the receiver must be told > there are no more values coming, such as to terminate a range loop. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/22539ffc-58e8-45fc-b270-b69014253474n%40googlegroups.com.