Java Garbage Collection Question and Answers

1. What is garbage collection?
 
  • If no reference to an object, that object is assumed to be no longer needed, and the memory occupied by the object can be reclaimed.
  • This is known as garbage collection.
 
Your Name Your Email-ID
Your Answer
2. What are the disadvantages of reference counting in garbage collection?
 
  • An advantage of this schema is that it can run in small chunks of time closely interwoven with the execution of the program.
  • This characteristic makes it particularly suitable for real time environments where the program can't be interrupted for very long.
  • A disadvantage of reference counting is that it does not detect cycles.
  • A cycle is two or more objects that refer to one another.
  • Another disadvantage is the overhead of incrementing and decrementing the reference count each time.
  • Because of these disadvantages, references counting currently is out of favor.
 
Your Name Your Email-ID
Your Answer
3. What class of exceptions are generated by the Java run time system?
  The Java runtime system generates Run time exception and Error exceptions.
 
Your Name Your Email-ID
Your Answer
4. Describe the Garbage Collection process in Java?
 
  • The JVM spec mandates automatic garbage collection outside of the programmer’s control.
  • The System.gc() or Runtime.gc() is merely a suggestion to the JVM to run the GC process but is NOT guaranteed.
 
Your Name Your Email-ID
Your Answer
1234 Page 1 of 4