Wednesday, February 4, 2009

Garbage Collection interview questions

<-Pre HomeNext->
Best Garbage Collection interview questions.

What is Garbage Collection.
Garbage collection is the process of automatically freeing objects that are no longer referenced by the program.
Garbage collection is also called automatic memory management as JVM automatically removes the unused variables/objects (value is null) from the memory.

Can be force JVM to free memory.
Although JVM automatically removes the unused variables/objects (value is null) from the memory.But it can be forced by calling System.gc() and Runtime.gc(), JVM tries to recycle the unused objects, but there is no guarantee when all the objects will garbage collected.There is no guarantee that Garbage collection will start immediately upon request of System.gc().

What kind of thread is the Garbage collector thread?
It is a daemon(run in background) thread .

If an object is garbage collected, can it become reachable again?
Once an object is garbage collected, It can no longer become reachable again.

Can an object’s finalize() method be invoked while it is reachable?
An object’s finalize() method cannot be invoked by the garbage collector while the object is still reachable. However, an object’s finalize() method may be invoked by other objects.

Does garbage collection guarantee that a program will not run out of memory? *IMP*
No. Garbage collection does not guarantee that a program will not run out of memory. It is possible for programs to use up memory resources faster than they are garbage collected. It is also possible for programs to create objects that are not subject to garbage collection.

^Back to top


What is the purpose of finalization?
The purpose of finalization is to give an unreachable object the opportunity to perform any cleanup, before the object gets garbage collected. ex. closing an opened database Connection.




Pre->Package
Next->Object Ser..

*****Please feel free to give feedback at shrawan.iitg@gmail.com and comments below *****

No comments:

Post a Comment