非解释语言可以有垃圾收集器吗?
非解释语言是否可能有垃圾收集器。 解释型语言让解释器逐行执行程序,因此解释器也可能提供带有 GC 的运行时。 但是,是否有可能为任何其他语言提供垃圾收集器,而无需在代码本身中构建 GC?
Is it possible for a Non-Interpreted language to have a Garbage collector. Interpreted languages have the Interpretor executing the Program line by line so the Interpretor might just as well provide a runtime with a GC. But is it possible to have a Garbage collector for any other language without building the GC in your code itself ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
垃圾收集只需要以特殊方式标记指针变量,以便运行时可以识别它们并用于垃圾收集。 它与解释/编译无关,而是需要特殊的运行时并为每个变量存储附加数据。
Garbage collection only requires the pointer variables be marked special way so that the runtime can identify them and use for garbage collection. It has nothing to do with interpretation/compilation, but instead requires special runtime and storing additional data with each variable.
好吧,.NET 语言(发送到 IL - C#、VB.NET、MC++ 等)不会被解释(特别是如果您使用 NGEN) - 并且具有完整的垃圾回收功能。
同样,Java。
Well, .NET languages (that emit to IL - C#, VB.NET, MC++, etc) aren't interpreted (especially if you use NGEN) - and has full garbage collection.
Likewise, Java.
是 - http://www.hpl.hp.com/personal/Hans_Boehm/gc /
Yes - http://www.hpl.hp.com/personal/Hans_Boehm/gc/
有关编译语言(在本例中为 C 和/或 C++)的实际实现,请参阅 http://www.hpl.hp.com/personal/Hans_Boehm/gc/
For an actual implementation in a compiled language, in this case C and/or C++, see the Boehm GC at http://www.hpl.hp.com/personal/Hans_Boehm/gc/
Haskell 具有垃圾收集功能,无论是编译为本机代码还是解释型代码。
Haskell has garbage collection, whether it's compiled to native code or interpreted.
新的 C++0x 包含使垃圾收集的实现更容易的功能。 例如,请参阅此采访。
The new C++0x includes features that make implementation of garbage collection easier. See this interview for example.
是的。
当智能指针引用计数变为零时,具有智能指针实现的 C++ 将进行垃圾收集。
你有垃圾收集。 您没有自己构建它。
Yes.
C++ with a smart pointer implementation will garbage collect as the smart pointer reference counts go to zero.
You have garbage collection. You did not build it yourself.
Objective-C 2 现在具有垃圾收集功能,并且也有可用于 C++ 的垃圾收集库。
我认为只要有语言允许您检查对象,这样您就可以遍历对象树,这是可能的。
Objective-C 2 has garbage collection now, and there are garbage collection libraries available for C++ as well.
I think it's possible as long as there is it the language allows you to inspect objects so you can traverse the object tree.