知识卡片
协程必须有明确退出条件
goroutine若永久等待无人发送的通道,就不会正常退出,栈和所引用对象也继续存活。垃圾回收只能处理不再可达的数据,不能替设计者判断一个仍在等待的任务已无业务用途。每次启动都要说明谁触发终止、阻塞点怎样解除,以及调用方提前离开时如何收尾。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Scalability · 查看原书依据
You should never start a goroutine without knowing how it will stop… Every time you use the go keyword in your program to launch a goroutine, you must know how, and when, that goroutine will exit. If you don’t know the answer, that’s a potential memory leak.”13 Forever Ticking Tickers Very often you’ll want to
参考来源
- 位置:《Cloud Native Go》第07章《Scalability》(来源项目book-sources;源文件:extracted/Cloud Native Go (Matthew A. Titmus)/_epub-src/OEBPS/ch07.xhtml)
- 结论依据:goroutine若永久等待无人发送的通道,就不会正常退出,栈和所引用对象也继续存活。原文相应定义、示例或限制为此结论提供依据;补充纠错与版本边界在正文就近标明。
- 原始内容:You should never start a goroutine without knowing how it will stop… Every time you use the go keyword in your program to launch a goroutine, you must know how, and when, that goroutine will exit. If you don’t know the answer, that’s a potential memory leak.”13 Forever Ticking Tickers Very often you’ll want to