malloc and free
are explicitly called in the program for dynamic management of memory. In case
of run time stack the memory management should be automatically done by the
calling sequence. Fully
dynamic runtime
environment automatically reclaim previous allocated blocks which are not used further
without explicit free call. This process is called as garbage collection.
Garbage collection can be achieved in any of the following methods
mark and sweep
stop and copy
generational
garbage collection
Mark and sweep: In
this method no memory is freed until malloc fails for insufficient memory. At
this point, the mark process marks the memory blocks whose values are not used
any more. In the sweep process the marked memory blocks are cleared and put
into free list. Some time memory compaction may be required in order to get
large free block.
Stop and copy:
In this method, the memory is divided into two halves and allocating storage
only from one half at a time. During the marking process all the updated blocks
(the blocks whose values are changed) are stored in second half. If performs
memory compaction automatically. Once all blocks in the used area have copied,
the used and unused halves of memory are interchanged and the processing continues.
Generational
garbage collection: The aim of this method is to reduce the delay. In order to
do this, the allocated objects that survive for long time are copied onto
permanent space and are not deallocated during reclaimation. This reduces the
search space for newer storage and hence reducing the time for searching.
0 comments