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
How do you create a bulleted list?
How do you write a good declaration?
Why does my function print none?
What are the java ide’s?
Why do we need hashset in java?
What is an escape character in java?
What are access specifiers available in java?
What is polymorphism java example?
Is a boolean 1 bit?
Can we force the garbage collection to run?
What is bufferedreader in java?
What is "this" keyword in java? Explain
What are the types of inner classes (non-static nested class) used in java?
How to restrict a member of a class from inheriting by its sub classes?
What is static import in java?