dsfdsf48652 2011-10-19 15:24
浏览 30
已采纳

Go使用哪种垃圾收集?

Go is a garbage collected language:

http://golang.org/doc/go_faq.html#garbage_collection

Here it says that it's a mark-and-sweep garbage collector, but it doesn't delve into details, and a replacement is in the works... yet, this paragraph seems not to have been updated much since Go was released.

It's still mark-and-sweep? Is it conservative or precise? Is it generational?

  • 写回答

5条回答 默认 最新

  • doushi1900 2011-10-19 16:04
    关注

    Plans for Go 1.4+ garbage collector:

    • hybrid stop-the-world/concurrent collector
    • stop-the-world part limited by a 10ms deadline
    • CPU cores dedicated to running the concurrent collector
    • tri-color mark-and-sweep algorithm
    • non-generational
    • non-compacting
    • fully precise
    • incurs a small cost if the program is moving pointers around
    • lower latency, but most likely also lower throughput, than Go 1.3 GC

    Go 1.3 garbage collector updates on top of Go 1.1:

    • concurrent sweep (results in smaller pause times)
    • fully precise

    Go 1.1 garbage collector:

    • mark-and-sweep (parallel implementation)
    • non-generational
    • non-compacting
    • mostly precise (except stack frames)
    • stop-the-world
    • bitmap-based representation
    • zero-cost when the program is not allocating memory (that is: shuffling pointers around is as fast as in C, although in practice this runs somewhat slower than C because the Go compiler is not as advanced as C compilers such as GCC)
    • supports finalizers on objects
    • there is no support for weak references

    Go 1.0 garbage collector:

    • same as Go 1.1, but instead of being mostly precise the garbage collector is conservative. The conservative GC is able to ignore objects such as []byte.

    Replacing the GC with a different one is controversial, for example:

    • except for very large heaps, it is unclear whether a generational GC would be faster overall
    • package "unsafe" makes it hard to implement fully precise GC and compacting GC
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊