|
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? |
Answered by
panjf2000
Sep 27, 2024
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. |
1 reply
Answer selected by
yugu2day
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.