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

Describe 2 different ways to concatenate two strings.

766


What ide should I use for java?

570


What is the symbol for space?

658


How to obtain a performance profile of java program

631


What is the base class of all exception classes in java?

666






If a class is declared without any access modifiers, where may the class be accessed in java programming?

773


What is a default constraint?

705


Why java is secure? Explain.

683


What is a flag and how does it work?

606


Can we overload the methods by making them static?

609


How many bytes are a float?

598


What is the difference between hashmap and hashtable? What is an interface?

632


What is the difference between replace and replace all?

576


What is the meaning of variables in research?

634


What is string data type?

641