0

Managed languages being the ones that handle memory cleanup for you.

EDIT I'm not talking about garbage collection. I was just interested in knowing about languages that would free() memory for me automatically, and still compile down to machine code.

Luca Matteis
  • 29,161
  • 19
  • 114
  • 169
  • 9
    "Managed" != "garbage collection" – John Saunders Jul 31 '09 at 15:05
  • 4
    "Managed" == "Sold By Microsoft", right? – S.Lott Jul 31 '09 at 15:07
  • Javascript compiles to native code. Explain what you are actually trying to achieve. – jrockway Jul 31 '09 at 15:10
  • "memory cleanup" != "garbage collection" – Luca Matteis Jul 31 '09 at 15:11
  • @Luca Matteis: John Saunders is right that "Managed" != "garbage collection". But automatic memory cleanup is basically the same thing as garbage collection (and yes, reference counting is a form of GC). – Zifre Jul 31 '09 at 15:40
  • @Zifre: I'd argue that reference counting *is not* necessarily GC unless you have a thread or subprocess (the "collector") that collects objects with zero references. If the object is free()d immediately after reaching zero references, it doesn't generate garbage, doesn't need a collector thread/subprocess, and thus should not be considered garbage collected. – Juliano Jul 31 '09 at 16:03

6 Answers6

9

You seem to be confusing "Managed" and "Garbage collection", while often managed languages (for example C# and Java) have automated garbage collection, "managed" actually refers to the fact that there is a "virtual machine" which executes your code (see http://en.wikipedia.org/wiki/Managed_code).

So for example the CLR (common language runtime) is the virtual machine executing .Net code, and the JVM (Java virtual machine) is the virtual machine executing java code.

You can in fact have Garbage collection for unmanaged languages (for example C++), and visa versa have managed languages without garbage collection (EDIT: I was looking for some but I can't seem to find any unless Objective C counts, I'm not sure it makes a huge amount of sense to create a managed language without garbage collection anyway)

Both of Java and C# can in fact be compiled directly into machine code, so they are executed directly and not using a virtual machine - for .Net code this is done using NGEN (in fact the CLR compiles .Net assemblies into machine code as you execute it, so-called "Just in time" compilation)

EDIT: As an update to the update of your question, there are in fact a number of alternatives to garbage collection in a spectrum between the extreme of complete manual memory management and garbage collection, and a lot of languages which compile to machine code incorporate varying forms of memory management which dont require you to explicitly free memory.

Can I ask - is this an "out of interest" question, or are you trying to select a language for a project - If the latter then why are you so interested in having your langauge compile down to machine code? Certainly in the case of .Net having your code JIT compiled offers a number of performance advantages (in the majority of cases), also NGENing your code doesn't remove the dependency on the .Net framework.

Justin
  • 84,773
  • 49
  • 224
  • 367
  • 1
    i'd consider 'managed' any language where there's a significant code running 'around' your code, checking any access violations, dangling pointer, array boundaries, etc. usually done with VM, but compiling guards would still fit. – Javier Jul 31 '09 at 15:17
  • You cannot have garbage collection in C++ in any sensible way. According to Stroustrup "the language is hostile towards GC" – EFraim Jul 31 '09 at 15:28
  • 1
    I'd agree with that, all the same "Managed" is kind of an of a subjective term. Your definition includes scripting languages, and wheras I'd agree with that I've never heard people refer to JavaScript as being "Managed" before :-) – Justin Jul 31 '09 at 15:29
8

lots:

LISP (and variants), Erlang, C# (under Mono), Haskell, Java (with gcj)

Javier
  • 60,510
  • 8
  • 78
  • 126
4

Sure there are. Java, for instance. (gcj)

However the term managed itself implies you have to carry some runtime around.

EFraim
  • 12,811
  • 4
  • 46
  • 62
  • 1
    Java VMs also use what they call JIT, meaning code gets compiled as it is executed and thus runs faster when called again. But that's probably not what Luca wants. – Stroboskop Jul 31 '09 at 15:15
  • @Stroboskop: gcj can compile to an executable without JIT. – Zifre Jul 31 '09 at 15:37
3

A few more, in the broader sense of "managed" meaning safe (via runtime type checking or exhaustive static analysis) and/or garbage collected:

  • OCaml
  • D
  • Ada
  • Prolog
  • Clean
  • Eiffel
fortran
  • 74,053
  • 25
  • 135
  • 175
1

Analog to Efraims's answer, any .NET program will compile to machine code as well, usually in 2 steps (JIT) but there is a NGEN tool to pre-compile the MSIL to native.

H H
  • 263,252
  • 30
  • 330
  • 514
1

There is a semi-GC choice : GLIB.

Gilb use reference count to manage lifespan of object. When refrence count meet 0, an object is cleaned.

It much much more inconvienient than .NET or Java or Python, but when you have to use C, it's better than nothing.

faceclean
  • 3,781
  • 8
  • 39
  • 58