Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a Non-Interpreted language have a Garbage Collector?

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 ?

like image 674
Geek Avatar asked May 06 '09 10:05

Geek


People also ask

Do all languages have garbage collectors?

Garbage collection is the process in which programs try to free up memory space that is no longer used by objects. Garbage collection is implemented differently for every language. Most high-level programming languages have some sort of garbage collection built in.

Which language does not have a garbage collector?

Primitive programming languages like C and C++ do not have their garbage collection instead expect the developer to not only allocate the object but also deallocate it explicitly. Hence we see the functions like "malloc" and "free".

Which languages have garbage collector?

Garbage collection (GC) is a memory recovery feature built into programming languages such as C# and Java.

Which variables are eligible for garbage collection?

An object is eligible to be garbage collected if its reference variable is lost from the program during execution. Sometimes they are also called unreachable objects. What is reference of an object? The new operator dynamically allocates memory for an object and returns a reference to it.


2 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.

like image 63
sharptooth Avatar answered Sep 30 '22 03:09

sharptooth


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.

like image 28
Marc Gravell Avatar answered Sep 30 '22 03:09

Marc Gravell