Question

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 ?

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

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 has garbage collection, whether it's compiled to native code or interpreted.

The new C++0x includes features that make implementation of garbage collection easier. See this interview for example.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top