Go使用哪种垃圾收集? [英] What kind of Garbage Collection does Go use?

查看:159
本文介绍了Go使用哪种垃圾收集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Go是一种垃圾回收语言:

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



这里说它是一个标记和清理垃圾收集器,但它不深入研究细节,并且正在进行更换......但是,自从Go发布以来,这一段似乎没有进行过更新。



这仍然是标记和-扫?它是保守的还是精确的?它是否是代数?

解决方案

Go 1.4的垃圾收集器的计划:




  • 混合停止世界/并发收集器

  • 停止世界部分受限于10毫秒截止日期

  • 专用于运行并发收集器的CPU内核

  • 三色标记和扫描算法 b
  • 非压缩

  • 完全精确

  • 如果程序正在移动指针,
  • 更低的延迟,但最有可能的吞吐量也低于Go 1.3 GC



Go 1.1上的垃圾回收器更新:


  • 并发扫描(导致更短的暂停时间)

  • 完全精确



  • Go 1.1垃圾收集器:




    • 标记和扫描(并行实现)
    • 非代数
    • 非压缩

    • mostl y精确(除堆栈框架外)
    • stop-the-world

    • 基于位图的表示形式

    • 零 - 当程序没有分配内存时(即:混洗指针与C一样快,尽管实际上这比C慢,因为Go编译器不像C编译器那样先进,比如GCC)
    • >
    • 支持定位器对象

    • 不支持弱引用



    与Go 1.1相同,Go 1.0垃圾回收器:



    • ,但垃圾收集器并不十分精确。保守的GC可以忽略诸如[]字节的对象。


    用另一个替换GC是有争议的,例如:除了非常大的堆之外,目前还不清楚代GC是否会更快整体


  • $ b
      不安全包使得很难实现完全精确的GC和压缩GC

    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?

    解决方案

    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

    这篇关于Go使用哪种垃圾收集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆