What Is Java Garbage Collection ?
Posted on December 17, 2009
Question: What Is Garbage Collection in Java Programming Language ?
Answer: Garbage Collection is automatic memory management.Its a case of resource management.
Many Programming Language Permit the Memory to be allocated dynamically at run-time.The Process of allocating memory varies based on the syntax of the language, but always involves returning a pointer to the starting address of a memory block.
After the allocated memory is no longer required the program or runtime environment should de-allocate the memory. In C,C++ and other languages, you are responsible for de-allocating the memory.This can be a difficult exercise at times,because you do not always know in advance when memory should be released.programs that do not de-allocate memory can crash eventually when there is no memory left on the system to allocate. These programs are said to have memory leaks.
The Java programming language removes you from the responsibility of de-allocating memory.It Provides a system -level thread that tracks each memory allocation.During idle cycles in the JVM, the garbage collection thread checks for and frees any memory that can be freed.
Garbage collection happens automatically during the lifetime of a Java technology program, eliminating the need to deallocate memory and avoiding memory leaks.However , garbage collection schemes can vary dramatically across JVM implementations.
Benefits of Garbage Collection in Java Programming
Garbage collection frees the programmer from manually dealing with memory allocation and deallocation. As a result, certain categories of bugs are eliminated or substantially reduced:
- Dangling pointer bugs, which occur when a piece of memory is freed while there are still pointers to it, and one of those pointers is then used.
- Double free bugs, which occur when the program attempts to free a region of memory that is already free.
- Certain kinds of memory leaks, in which a program fails to free memory occupied by objects that will not be used again, leading, over time, to memory exhaustion.
Looking for a Fresher Job? Post Your Resume Free !!!
More Articles From "Java" Category
- What is Collection API in Java?
- What is Abstraction in Java ?
- What is Inheritance in Java ?
- What Is Polymorphism In Java ?
- What Is Java Virtual Machine or JVM ?
- What Is Java Technology?