Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Differences between traditional programming language and object oriented programming language?

1059


What is the major difference between linkedlist and arraylist?

962


What does .equals do in java?

1006


How does multithreading take place on a computer with a single cpu?

949


What is the symbol for average?

974


How do you read and print a string in java?

906


How does linkedhashmap work in java?

932


What is the latest version of java?

1051


What is the protected method modifier?

988


When is the garbage collection used in Java?

1126


What is function declaration?

913


Does variable declaration allocate memory?

982


What is native method in java?

1013


How do you declare a variable?

1037


What causes memory leaks in java?

871