-
I found that when purging/resetting the workers, simply setting it to nil and sending nil to the task channel so that it can stop the for range loop in the worker's run function.
However, the task channel remains open although it can be garbage collected finally. But why don't we close it directly? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Like you said, there wouldn't be any memory leaks, so why should we bother to close it? I don't see any obligated instructions about closing the used channels in the Go specification and effective Go. Generally speaking, we need a reason to do something more than a reason not to do something. |
Beta Was this translation helpful? Give feedback.
Like you said, there wouldn't be any memory leaks, so why should we bother to close it? I don't see any obligated instructions about closing the used channels in the Go specification and effective Go. Generally speaking, we need a reason to do something more than a reason not to do something.