Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any compiled language that has garbage collection built in?

Is there any compiled language that has garbage collection built in?

To my understanding right now, the purpose of an interpreter or JVM is to make binaries platform independent. Is it also because of the GC? Or is GC possible in compiled code?

like image 912
Thomas Avatar asked Nov 27 '22 11:11

Thomas


2 Answers

SML, OCaml, Eiffel, D, Go, and Haskell are all statically-typed languages with garbage collection that are typically compiled ahead of time to native code.

like image 125
munificent Avatar answered Jan 08 '23 03:01

munificent


As you correctly point out, virtual machines are mostly used to abstract away machine-dependent properties of underlying platforms. Garbage collection is an orthogonal technology. Usually it is not mandatory for a language, but is considered a desired property of a run-time environment. There are indeed languages with primitives to allocate memory (e.g., new in Java and C#) but without primitives to release it. They can be thought of as languages with built-in GC.

One such programming language is Eiffel. Most Eiffel compilers generate C code for portability reasons. This C code is used to produce machine code by a standard C compiler. Eiffel implementations provide GC (and sometimes even accurate GC) for this compiled code, and there is no need for VM. In particular, VisualEiffel compiler generated native x86 machine code directly with full GC support.

like image 35
Alexander Kogtenkov Avatar answered Jan 08 '23 04:01

Alexander Kogtenkov