What is garbage collection in Java, and how can it be used ?
Answer Posted / praveen thakur suryavanshi
The JVM's heap stores all objects created by an executing
Java program. Objects are created by Java's "new" operator,
and memory for new objects is allocated on the heap at run
time. Garbage collection is the process of automatically
freeing objects that are no longer referenced by the
program. This frees the programmer from having to keep track
of when to free allocated memory, thereby preventing many
potential bugs and headaches.
The name "garbage collection" implies that objects that are
no longer needed by the program are "garbage" and can be
thrown away. A more accurate and up-to-date metaphor might
be "memory recycling." When an object is no longer
referenced by the program, the heap space it occupies must
be recycled so that the space is available for subsequent
new objects. The garbage collector must somehow determine
which objects are no longer referenced by the program and
make available the heap space occupied by such unreferenced
objects. In the process of freeing unreferenced objects, the
garbage collector must run any finalizers of objects being
freed.
| Is This Answer Correct ? | 4 Yes | 3 No |
Post New Answer View All Answers
Should you use singleton pattern?
What is e in java?
This abstract class is correct ? abstract class A { public abstract void Disp(); public abstract void B() { } public absract virtual C() { } }
Difference between predicate, supplier and consumer ?
what do you understand by synchronization? : Java thread
From the two, which would be easier to write: synchronization code for ten threads or two threads?
What is rule of accessibility in java?
What is the difference between serializable and externalizable interface?
How many bytes is 255 characters?
Similarity and difference between static block and static method ?
When should I use singleton?
What is java used for?
how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? : Java thread
What is stringjoiner ?
What is an immutable class?