when is an object ready to be garbage collected by the compiler.is it the same way all the time
Printable View
when is an object ready to be garbage collected by the compiler.is it the same way all the time
Which the object is no longer needed in a particular application,that time tat object will be garage collected
Garbage collector is usefull to overcome memory crashes.so whenever it thinks any object is not usefull then it will be removed from the memory so it is collected by garbage collector
Any Object that is not accessble by any LIVE thread(i.e active thread) then the garbage collector calls the finaliz() method on that object to release the acquired resourec before garbage collecting the Object.Once resorces released then the object is garbage collected .Pls feel free to ask for further expalnation.
@srini235
But what if other threads are referring to that object somehow?
There are different implementation for garbage collection, one popular method is mark-and-sweep algorithm, where jvm puts objects in a graph, and traverse the graph based on if live thread exists from one object to other object. If there is no live thread, then jvm "mark" the object, and then "sweep" it off graph. Hence, the name is "mark-and-sweep".if there are other threads referring to the same object, then it won't be allocated. There are also ome advanced garbage collection implementation. You can read it in advanced java book senior computer science engineering student donald bren of information and computer science
university of california, irvine
Which the object is no longer used
when resoures linked with that object are not required for later
everything is ok with garbage collector but a little doubt is there
can we see the object functionality after removing from memeoiry
when there is no refrence pointing to that object& the object remains unreachable