0

What is the exact process of garbage collection in JAVA. Its so confusing in the notes.

Garbage collection in JAVA

13th Jun 2017, 3:54 AM
Manish Jha
Manish Jha - avatar
4 Respuestas
+ 6
Just a memory manager. Everything in Java is object. So, whenever an object is destroyed, the memory it consumed should be unallocated to be used by some other objects. This task is done by Garbage Collector. You might be confused with the name, why it is called garbage? It is because when an object gets free, the memory it consumed become useless and since the object doesn't exist, their is no possibility to access the memory location, so the memory space become a place which contains garbage.
13th Jun 2017, 4:08 AM
Sachin Artani
Sachin Artani - avatar
+ 4
When an object becomes an 'Orphan' the garbage collector 'picks it up' to free up memory. New objects can then use this memory. It is essentially automatic memory management.
13th Jun 2017, 4:04 AM
Rrestoring faith
Rrestoring faith - avatar
+ 3
@Manish By orphan I basically mean unreachable, or no reference. Here's an example from a post from stackOverFlow: "Integer i = new Integer(4); // the new Integer object is reachable via the reference in 'i' i = null; // the Integer object is no longer reachable" So the Integer object will be ready when the garbage collector is.
13th Jun 2017, 4:20 AM
Rrestoring faith
Rrestoring faith - avatar
0
Can you please explain what exactly is an 'Orphan' object?
13th Jun 2017, 4:06 AM
Manish Jha
Manish Jha - avatar