Домой United States USA — software Garbage Collection in Java (JVM)

Garbage Collection in Java (JVM)

211
0
ПОДЕЛИТЬСЯ

Garbage Collection in Java automatically allocates and deallocates memory, so that developers don’t need to write an explicit program to do memory management.
Join the DZone community and get the full member experience. Garbage Collection in Java automatically allocates and deallocates memory, so that developers don’t need to write an explicit program to do memory management, which is one of the main advantages of Java programming. Whenever a Java program runs on the JVM, the objects are created on the heap and are a portion of memory that is dedicated to the program. Eventually, some objects will no longer be needed. The garbage collector finds these unused objects and deletes them to free up memory. The garbage collector will look at heap memory, identifying which objects are in use and which are not, and deleting the unused objects. An in-use object, or a referenced object, means that some part of your program still maintains a pointer to that object. An unused object, or unreferenced object, is no longer referenced by any part of your program. So the memory which is used by an unreferenced object can be reclaimed by performing a Garbage Collection. Deallocation of memory can be described in 3 basic processes: Marking — Process of identifying the pieces of memory which are in use and are not by Garbage collector and is the first step Normal Deletion — Process of removing unreferenced objects leaving referenced objects and pointers to free space. Deletion with Compacting — In addition to deleting unreferenced objects, it will compact the remaining the referenced objects by moving the objects together to make thenew memory allocation much easier and faster.

Continue reading...