Thomas
Thomas

Reputation: 6196

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?

Upvotes: 7

Views: 6847

Answers (4)

Dmitry Ponyatov
Dmitry Ponyatov

Reputation: 346

https://nim-lang.org

Nim language has some progress and has good portability as uses C(++), JS & ObjectiveC code generation

Upvotes: 2

Shannon Cornish
Shannon Cornish

Reputation: 961

Garbage collection is possible in compiled languages.

The Boehm GC is a well known garbage collector for C & C++ - Wikipedia article

Another example is the D programming language has garbage collection

Upvotes: 3

munificent
munificent

Reputation: 12364

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.

Upvotes: 21

Alexander Kogtenkov
Alexander Kogtenkov

Reputation: 5780

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.

Upvotes: 11

Related Questions