7

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?

1
  • 3
    Java and .NET are compiled. Perhaps you're asking about languages that are compiled to native code? Commented Jan 10, 2014 at 14:07

4 Answers 4

22

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.

Sign up to request clarification or add additional context in comments.

Comments

12

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.

Comments

3

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

2 Comments

Mozilla's Rust has GC too but it's optional.
What is the best tutorial on embedding Boehn in C and C++ applications?
2

https://nim-lang.org

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.