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
Explain aggregation in java?
What is overloading and overriding in java?
What are loops in java?
What is the use of static methods?
Suppose if we have variable ' I ' in run method, if I can create one or more thread each thread will occupy a separate copy or same variable will be shared?
How do you sort in ascending order in java?
What is widening and narrowing in java? Discuss with an example.
Give an example of use of pointers in java class.
What is the method to declare member of a class static?
Is java hard to learn?
What is a arraylist in java?
What is multiple inheritance? Is it supported by java?
What is boolean strategy?
What is ternary operator?
extending thread class or implementing runnable interface. Which is better? : Java thread