What is garbage collection in Java, and how can it be used ?
Answer Posted / prashant srivastava the great
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 ? | 2 Yes | 1 No |
Post New Answer View All Answers
What is another word for methodology?
State the merge-sort principle and its time complexity.
What happens when I use / and % with a negative numerator?
Write a java program to check if a number is prime or not?
How do I convert a numeric ip address like 192.18.97.39 into a hostname like java.sun.com?
what is singleton class in java?
Can a boolean be null java?
Can a static class have a constructor?
Given a singly linked list, find the middle of the list in a single traversal without using temporary variable.
What is the purpose of final keyword and when to use it?
Implement 2 stacks with just 1 array. The stack routines must not indicate overflow unless every slot in array is used.
What is the purpose of the System class?
What is array length?
Who is the owner of java?
Which is better list or arraylist in java?