mils
mils

Reputation: 1916

A programming language with garbage collection AND manual memory management

Are there any programming languages out there that use garbage collection, but that also allow for manual memory management? So for example, providing a destructor function. Is it even possible for a programming language to have garbage collection and manual memory management concurrently?

Related SO question here, but no answer: Interpreted languages with manual memory management?

Thanks

Upvotes: 4

Views: 981

Answers (1)

Speakjava
Speakjava

Reputation: 3400

It's definitely possible, but it requires the language to support the allocation of objects (assuming it's an OO language, which certainly makes life easier) from two (or more) areas of memory.

An example of a platform that supports this is the Real Time Specification for Java (RTSJ). Since real-time operation can easily be disturbed by a non-deterministic GC RTSJ adds areas of memory outside of the standard Java heap that can be used by application code. RTSJ uses the concept of a memory area, of which there are three: HeapMemory, ScopedMemory and ImmortalMemory. ScopedMemory allows a region of memory to be used by a specific thread. When the thread terminates the area of memory is automatically freed. This relies on the developer being careful not to share references to this area outside the thread. ImmortalMemory is a region of memory that will never be garbage collected. Once objects are allocated in this region it is not possible to reclaim the space (there is no free() call).

I disagree with the comment that C and C++ are languages that match your description. Neither runs in a managed environment so neither has any form of concurrent GC.

Upvotes: 3

Related Questions