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 ?
- 6I wonder if you're assuming a false dichotomy between "interpreted" and "native". Java and C#, for example, are neither "interpreted" nor "native" - they run (essentially) in a VM, but from an IL.Marc Gravell– Marc Gravell2009-05-06 10:31:22 +00:00Commented May 6, 2009 at 10:31
- Can you please Explain more :?Geek– Geek2009-05-06 10:36:43 +00:00Commented May 6, 2009 at 10:36
- For that conversation, see the comments on my reply.Marc Gravell– Marc Gravell2009-05-06 10:51:10 +00:00Commented May 6, 2009 at 10:51
8 Answers
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 Comments
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.
17 Comments
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/
Comments
The new C++0x includes features that make implementation of garbage collection easier. See this interview for example.
Comments
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.
7 Comments
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.