What is garbage collection in Java, and how can it be used ?

Answers were Sorted based on User's Feedback



What is garbage collection in Java, and how can it be used ?..

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

What is garbage collection in Java, and how can it be used ?..

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

What is garbage collection in Java, and how can it be used ?..

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

What is garbage collection in Java, and how can it be used ?..

Answer / birhane mehari

yes

Is This Answer Correct ?    0 Yes 0 No

What is garbage collection in Java, and how can it be used ?..

Answer / rahulmishra642

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

What is garbage collection in Java, and how can it be used ?..

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

What is garbage collection in Java, and how can it be used ?..

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

What is garbage collection in Java, and how can it be used ?..

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

What is garbage collection in Java, and how can it be used ?..

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

What is garbage collection in Java, and how can it be used ?..

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

Post New Answer

More Core Java Interview Questions

how to minimize the functionality to will not force garbage collector?

2 Answers  


Is passing by reference faster?

0 Answers  


What is the difference between a constructor and a method?

0 Answers  


Can You Have Virtual Functions In Java?

0 Answers  


What is the difference between interface & abstract class?

0 Answers  






What is the difference between @before and @beforeclass annotation?

0 Answers  


is it possible to add a object in a HASHMAP

6 Answers   HCL,


Why does java not support operator overloading?

0 Answers  


What is immutable class? how to make a Class explicitly "Immutable"?Wap to make a class explicitly immutable.

3 Answers  


In a my eclipse editor if i want to switch from jdk 1.4 to jdk 1.6 how to do that???? Initially i have jdk1.4

1 Answers   Tech Mahindra,


What is the purpose of lambda expressions?

0 Answers  


Can a Byte object be cast to a double value?

3 Answers   KO,


Categories