duange2971 2015-02-28 02:52
浏览 18
已采纳

谁进行垃圾收集工作?

According to this specification, there is a mark-and-sweep garbage collection mechanism behind go. But who does it?

  • Go code will compile to native binary, right? So there will not be a virtual machine like Java which it could rely on. So who does this dirty work for us? A cryptic thread? Or just a goroutine?

  • Will the garbage collecting procedure stop-the-world like a full GC of Java? And could any one tell the difference of GC mechanisms between Java and Go? I could find rarely material on the net.

  • 写回答

1条回答 默认 最新

  • doueta6642 2015-02-28 03:11
    关注

    Many of your questions are answered here:

    For the rest:

    But who does it?

    Native code runtime libraries provided by the Go implementation.

    (I haven't looked at the implementation, but it is hard to imagine that you could implement a high-performance GC for Go "above the line" in the Go language.)

    Go code will compile to native binary, right?

    Correct. The Go FAQ says so clearly.

    So there will not be a virtual machine like Java which it could rely on.

    Correct. However, that makes no difference. In the Java case, the GC is also implemented by native code libraries provided by the Java runtime.

    So who does this dirty work for us? A cryptic thread? Or just a goroutine?

    Well from Go 1.1 onwards, the GC is parallel so there must be some kind of multi-threading going on behind the scenes. Goroutines are a Go language concept, and it is hard to image that you would use them "below the line" in the native code GC implementation. (But I could be wrong ...)

    But you also need to understand that goroutines also entail multiple threads under the hood. The FAQ says:

    "Why doesn't my multi-goroutine program use multiple CPUs?

    You must set the GOMAXPROCS shell environment variable or use the similarly-named function of the runtime package to allow the run-time support to utilize more than one OS thread."

    See? Native / OS threads are involved under the hood.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来