What is garbage collection in Java, and how can it be used ?

Answer Posted / surinder mehra

Garbage Collection for an object occurs in following cases:

1) All references of that object explicitly set to null
e.g. object = null
2) Object is created inside a block and reference goes out
scope once control exit that block.
3) Parent object set to null, if an object holds reference
of another object and when you set container object's
reference null, child or contained object automatically
becomes eligible for garbage collection.

Garbage Collectors are implicitly invoked by JVMs when
needed(when there is no enough space for coming objects to
store). or jvm can call garbage collectors whenever it
finds that object is not being used for long time. It is
marked as garbage and later on collected

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is singleton service?

506


What is difference between static and abstract class?

516


Can we have multiple catch block for a try block?

584


What is string substring?

559


What are different types of encoding?

578






What is initial size of arraylist in java?

534


Is java type safe?

507


Why java is called not pure object oriented language?

575


What is the exact difference in between Unicast and Multicast object? Where will it be used?

580


What is dot operator?

572


What is return null in java?

507


Enlist few advantages of inheritance?

580


What all methods are used to prevent thread execution ?

549


What occurs when an object is constructed?

567


What is return in java?

552