Thursday, August 11, 2005

Memory Management in JVM

There are three type usually associated with VM.

1) Static memory management: - Here everything is allocated statically. All memory areas are allocated statically before execution begins. In this method the memory space for function parameter is also allocated before execution. This is not a good strategy for a VM implementation since it restricts use of recursive calls, it doesn’t allow multithreading. This strategy generally doesn’t allow any change to data structure at runtime.

2) Linear memory management: - Memory is allocated and freed in LIFO (Last In First Out) order. New object can be allocated space very easily. But for deleting old object’s memory space all new object’s memory space has to be deleted. This is used in very simple VMs. Since many data object in VM are managed in stack like structure.

3) Dynamic memory allocation: - Memory can be allocated in any order. Allocation takes place from special area which is known as heap. Memory once allocated is not fixed; size of the object can grow or shrink on the fly. Most of the modern VM use some form of the dynamic memory management. It can be either automatic or manual. Whenever programmer has responsibility of freeing the unused memory space explicitly like in c free (), this called as manual dynamic memory management. But if all allocation and de-allocation of memory done by VM without programmers intervention, this is called as automatic dynamic memory allocation.

3a) Automatic Dynamic Memory Management: - Programmers are free from all worry of allocation and de-allocation of object’s memory space. Garbage collector comes into picture in this method which reclaims unused (unreferenced) memory space. Memory system automatically expands and shrinks data in the heap as necessary. Benefits of this system include making programming easier, no dangling pointer and improve program reliability and safety. Implementation challenges for automatic memory management are keeping tracks of pointer to memory space, deleting memory space allocated to an object i.e. garbage collection, whether to compact heap whenever object memory space is deleted

0 Comments:

Post a Comment

<< Home