Posts

Showing posts with the label memory management

Java Memory Management

Image
Garbage Collection: Garbage Collection is the process of freeing space in the heap for the allocation of new objects. One of the best features of Java is automatic garbage collection.  Garbage Collector is the program running in the background that looks into all the objects in the memory and find out objects that are not referenced by any part of the program. All these unreferenced objects are deleted and space is reclaimed for allocation to other objects. One of the basic ways of garbage collection involves three steps: Marking:   This is the first step where the garbage collector identifies which objects are in use and which ones are not in use Normal Deletion:  Garbage collector removes the unused objects and reclaims the free space to be allocated to other objects Deletion with compacting:  For better performance, after deleting unused objects, all the survived objects can be moved to be together. This will increase the performance of allocation of memory to newer objects Java Mem