Garbage Collector
The JVM usually runs the garbage collector when the level of available memory is low. However, the garbage collector cannot ensure that there will always be enough memory. If there is not enough memory even after the garbage collector reclaims memory, the JVM throws an OutOfMemoryError exception. Note that the JVM will definitely run the garbage collector at least once before throwing this exception. While you can request that the garbage collector run, it is important to note that you can never force this action.
An object is eligible for garbage collection when no live thread can access it.An object can become eligible for garbage collection in different ways:
1> If the reference variable that refers to the object is set to null, the object becomes eligible for garbage collection, provided that no other reference is referring to it.
2> If the reference variable that refers to the object is made to refer to some other object, the object becomes eligible for garbage collection, provided that no other reference is referringto it.
3> Objects created locally in a method are eligible for garbage collection when the method returns, unless they are exported out of the method (that is, returned or thrown as an exception).
4> Objects that refer to each other can still be eligible for garbage collection.
0 Comments:
Post a Comment
<< Home