如果我从不检查其状态,是否可以让 Go 通道永远打开(永远不要关闭通道)?会不会导致内存泄漏?下面的代码可以吗?
func (requestCh chan<- Request) GetResponse(data RequestData) Response {
reply := make(chan Response)
requestCh <- Request{data: data, replyCh: reply}
return <-reply
}
原文由 Kluyg 发布,翻译遵循 CC BY-SA 4.0 许可协议
可以让 Go 通道永远打开并且永远不要关闭它。当通道不再被使用时,它将被垃圾收集。