Java Reference
In-Depth Information
a pointer is not, we may retain an object that is really dead, but we will find
all valid pointers, and never incorrectly collect a live object. We may mistake
an integer (or a floating value, or even a string) as a pointer, so compaction in
any form cannot be done. However, mark-sweep collection will work.
Garbage collectors that work with ordinary C programs have been devel-
oped [BW88]. User programs need not be modified. They simply are linked
to di
erent library routines, so that malloc and free properly support the
garbage collector. When new heap space is required, dead heap objects may
be automatically collected, rather than relying entirely on explicit free com-
mands (though frees are allowed, they sometimes simplify or speed heap
reuse).
With garbage collection available, C programmers need not worry about
explicit heap management. This reduces programming e
ff
ort and eliminates
errors in which objects are prematurely freed, or perhaps never freed. In
fact, experiments have shown [ZG92] that conservative garbage collection
is very competitive in performance with application-specific manual heap
management.
ff
12.5 Region-Based Memory Management
Stack allocation is straightforward to implement and exhibits predictable, min-
imal overheads. However, it is inflexible when compared to heap allocation;
all of the objects in a stack frame exist for the lifetime of a particular proce-
dure activation. Heap allocation is more flexible than stack allocation, but
requires careful implementation. Heap management also depends on garbage
collection, which may introduce unpredictable latencies in program execu-
tion, or intricate manual storage management, which can lead to subtle and
devastating bugs.
Region-basedmemorymanagement aims to combine the predictable per-
formance of stack allocation with the flexibility of heap allocation. Region-
based memory management is an automated technique and, like garbage
collection, is immune to dangling pointer errors. Unlike heap allocation with
garbage collection, though, region-based memory management does not need
to stop the program to free unused memory. As such, it can be particularly
suitable for real-time applications with latency requirements.
A region , like a heap, is an area of memory in which new objects can be
allocated as they are needed. The major di
erence between regions and heaps
is that it is impossible to deallocate an individual object from a region. Rather,
an entire region is deallocated at once. Therefore, a region may grow in size,
but it will never shrink.
Region-based approaches to memory management require that programs
are annotatedwith region creation and deletion operations, and that allocation
ff
 
 
Search WWH ::




Custom Search