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 is java console application?
As a developer what steps do you take to improve the performance?
Which collection object is faster to retrieving the data and inserting the data into it.
2 Answers Jamcracker, Virtusa,
What is the difference between length and length () in java?
Which is bigger float or double?
Does garbage collection guarantee that a program will not run out of memory?
How the threads are synchronized?
What is size_t?
How many types of memory areas are allocated by jvm?
What are the special characters?
What is the use of a conditional inclusion statement in Java ?
Tell us something about set interface.