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 ?
非解释语言是否可能有垃圾收集器。解释语言让解释器逐行执行程序,因此解释器也可以为GC提供运行时。但是,如果没有在代码本身中构建GC,是否可以为任何其他语言使用垃圾收集器?
8 个解决方案
#1
Yes.
C++ with a smart pointer implementation will garbage collect as the smart pointer reference counts go to zero.
随着智能指针引用计数变为零,带有智能指针实现的C ++将进行垃圾收集。
You have garbage collection. You did not build it yourself.
你有垃圾收集。你没有自己构建它。
#2
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.
垃圾收集只需要将指针变量标记为特殊方式,以便运行时可以识别它们并用于垃圾收集。它与解释/编译无关,而是需要特殊的运行时并为每个变量存储附加数据。
#3
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.
好吧,.NET语言(发出IL-C#,VB.NET,MC ++等)不被解释(特别是如果你使用NGEN) - 并且有完整的垃圾收集。
Likewise, Java.
#4
Yes - http://www.hpl.hp.com/personal/Hans_Boehm/gc/
是的 - http://www.hpl.hp.com/personal/Hans_Boehm/gc/
#5
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/
有关使用编译语言(在本例中为C和/或C ++)的实际实现,请参阅http://www.hpl.hp.com/personal/Hans_Boehm/gc/上的Boehm GC
#6
Haskell has garbage collection, whether it's compiled to native code or interpreted.
Haskell有垃圾收集,无论是编译为本机代码还是解释。
#7
The new C++0x includes features that make implementation of garbage collection easier. See this interview for example.
新的C ++ 0x包含的功能使垃圾收集的实现更容易。例如,请参阅此访谈。
#8
Objective-C 2 has garbage collection now, and there are garbage collection libraries available for C++ as well.
Objective-C 2现在有垃圾收集,并且还有可用于C ++的垃圾收集库。
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.
我认为只要有语言允许你检查对象就可以遍历对象树。
#1
Yes.
C++ with a smart pointer implementation will garbage collect as the smart pointer reference counts go to zero.
随着智能指针引用计数变为零,带有智能指针实现的C ++将进行垃圾收集。
You have garbage collection. You did not build it yourself.
你有垃圾收集。你没有自己构建它。
#2
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.
垃圾收集只需要将指针变量标记为特殊方式,以便运行时可以识别它们并用于垃圾收集。它与解释/编译无关,而是需要特殊的运行时并为每个变量存储附加数据。
#3
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.
好吧,.NET语言(发出IL-C#,VB.NET,MC ++等)不被解释(特别是如果你使用NGEN) - 并且有完整的垃圾收集。
Likewise, Java.
#4
Yes - http://www.hpl.hp.com/personal/Hans_Boehm/gc/
是的 - http://www.hpl.hp.com/personal/Hans_Boehm/gc/
#5
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/
有关使用编译语言(在本例中为C和/或C ++)的实际实现,请参阅http://www.hpl.hp.com/personal/Hans_Boehm/gc/上的Boehm GC
#6
Haskell has garbage collection, whether it's compiled to native code or interpreted.
Haskell有垃圾收集,无论是编译为本机代码还是解释。
#7
The new C++0x includes features that make implementation of garbage collection easier. See this interview for example.
新的C ++ 0x包含的功能使垃圾收集的实现更容易。例如,请参阅此访谈。
#8
Objective-C 2 has garbage collection now, and there are garbage collection libraries available for C++ as well.
Objective-C 2现在有垃圾收集,并且还有可用于C ++的垃圾收集库。
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.
我认为只要有语言允许你检查对象就可以遍历对象树。