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
what is the purpose of "virtual"?
Can we have try block without catch block?
What do you mean by scope of variable?
What are triggers in DB? Explain their types. How do they work?
Do extraneous variables affect validity?
What is meant by tab pans?
Who is the owner of java?
Why are global variables used?
How a variable is stored in memory?
Are arrays passed by reference in java?
What does a method signature consist of?
Why are lists ordered in java?
Explain constructors and types of constructors in java.
How do you use find and replace?
What are the 4 versions of java?