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


Please Help Members By Posting Answers For Below Questions

what is instanceof operator used in java?

582


What data structures are used to perform recursion?

593


How do you remove an object from an arraylist in java?

452


Why is the type for real numbers called double?

536


What are different ways of object creation in java ?

562






Give us a program to check for parenthesis matching using stack.

550


what happens when a thread cannot acquire a lock on an object? : Java thread

530


What do you mean by order of precedence and associativity?

537


Who developed java?

556


What is the hashcode () and equals () used for?

526


who can i handle multiple client in RMI

1431


What is dynamic binding(late binding)?

578


What is variable and constant explain with example?

522


What is the final variable?

570


How do you access command-line arguments within the code?

563