1.

Memory Management in Java

Answer»

Memory Management is a vital part of Java and it is very important to understand it. The memory in Java is divided into two MAIN parts, the stack and the heap. A diagram that demonstrates this is given as follows:

Details about the stack and the heap memory in Java is given as follows:

Stack Memory in Java

The Stack memory in Java is used for thread execution. Specific values are stored in the thread stack that are available for a short time. Also, stack memory may contain DATA references to objects GETTING referred from the method that are in the heap memory.

The order in Thread Stack memory is Last In First Out (LIFO). A block is created in the stack memory for all the primitive values and references to other objects in a method when that method is invoked. After the end of the method, the memory block in the stack memory is free and can be used by another method.

Heap Memory in Java

The heap memory in Java is memory allocated  to the Objects and the JRE CLASSES by the Java runtime. All the objects in the application are created in the heap memory. The objects in the heap memory are globally accessible from any place in the application and so they have a lifetime for the whole application execution.



Discussion

No Comment Found