What is garbage collection in Java, and how can it be used ?
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / sudeep baranwal
Garbage collection is reclaiming the unused memory by the invalid objects.Garbage collection is thread when its work unused memory Created objects from the memory.Garbage collection for responsible this process.
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / rana.ankur
Garbage collection is a method of jvm.In JAVA when object
iis not use in otherway there is no refrence to that object
it is ellegible for Garbage collection.
demon thread is used and its is known as Garbage
collectior..
and finalize method are also invoke to give last chance to
object to save it imprtant data..thanking you
| Is This Answer Correct ? | 0 Yes | 0 No |
1>Garbage collection is a deamon thread which runs at the background to support the nin deamon thread.
2>garbage collector is responsible to destroy the useless objects.
3>An obejct is eligible for GC if and only if it doesn;t have any reference.
4>we can also call GC explicitly by System Class and Runtime class
By System Class:
- System.gc();
By Runtime Class
-Runtime r = Runtime.getRuntime(); (here we are creating runtime object by using factory method)
now, you can call gc() method
-r.gc();
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / tulsi
Garbage collection means deallocation of variables,which
are of no use(variables that wont be usefull in future).It
is a automatic process that occurs during the execution of
your program. In other lanuages this facility is not
provided, we have to do it mannually where as java provides
this process known as garbage collection.
| Is This Answer Correct ? | 4 Yes | 5 No |
Answer / sandeep chaudhary
garbage collection is just a thread that is used for
deallocation of object.object in java are allocated in
heap area(memory ) ,particular object is not used for long
period then automatically garbage coolection calls this
object for destroyed.........
| Is This Answer Correct ? | 4 Yes | 5 No |
Answer / sachin deshmukh
In java doesn't allow memory leakage,Garbage collector
automatically deallocates memory.It deallocates memory of
objects that no longer has any references i.e. references
count is zero.
| Is This Answer Correct ? | 4 Yes | 5 No |
Answer / nitin kumar
Garbage collection is a system level thread that tracks each
memory allocation. During the idle cycles in the JVM, the
garbage collection thread check for and frees memory that
can be freed. It happen automatically during the lifetime of
a Java Technology program.
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / samji
When a Java object becomes unreachable to the program, then
it is subjected to garbage collection. The main use of
garbage collection is to identify and discard objects that
are no longer needed by a program so that their resources
can be reclaimed and reused.
| Is This Answer Correct ? | 4 Yes | 6 No |
What modifiers are used with a top level class?
Is Constructor possible in abstract class in java ?
What is object in java?
Differentiate between a class and an object.
Program to find greatest prime number in n numbers?
What is concurrent hashmap and its features?
Explain about exception propagation?
What is the use of singleton?
What are the two ways you can synchronize a block of code?
how to make the double-tone class ? as we have singletone class..?
What is exception in java?
aabccdee Find the used alphabets as abcde ?