JavaBeat Certifications Certifications Kits Articles Interview Questions OCAJP 7 OCPJP 5 OCPJP 6 OCEJWCD 6 SCBCD 5.0 SCEA SCJA

SCJP: Garbage Collection

Topic :
Feedback Request New QnA Print Email

Garbage Collection

  • Java itself does memory management. You do not need to allocate memory at the time of object creation; also you do not need to free memory explicitly
  • Object is created either on the heap or on a stack
  • Memory heap: Objects created with new keyword are placed in heaps. This memory remains allocated throughout the life cycle of the object. When the object is no more referred, the memory becomes eligible for garbage collection
  • Stack: During method calls, objects are created for method arguments and method variables. These objects are created on stack. Such objects are eligible for garbage-collection when they go out of scope.
  • Garbage Collection is a low-priority thread in java
  • Garbage Collection cannot be forced explicitly. JVM may do garbage collection if it is running short of memory.
  • The call System.gc() does NOT force the garbage collection but only suggests that the JVM may make an effort to do garbage collection.
  • Garbage Collection is hardwired in Java runtime system. Java runtime system keeps the track of memory allocated. Therefore, it is able to determine if memory is still usable by any live thread. If not, then garbage collection thread will eventually release the memory back to the heap.
  • Garbage Collection usually adopts an algorithm, which gives a fair balance between responsiveness (how quickly garbage-collection thread yields?) and speed of memory recovery (important for memory-intensive operations). Responsiveness is especially important in real time systems.
  • An object is eligible for garbage collection when no object refers to it.
  • An object also becomes eligible when its reference is set to null. (Actually all references to the object should be null for it to be eligible.)
  • The objects referred by method variables or local variables are eligible for garbage collection when the method or their container block exits

Topic :
Feedback Request New QnA Print Email

All api java java 6.0 java 7.0 jdbc jsp servlet ejb jndi jms ejb 3.0 j2ee jee 5.0 jee 6.0 jsf struts spring Hibernate ajax JBoss Seam netbeans eclipse ant xml maven dojo junit javafx j2me log4j ESB JBoss Apache Quartz scjp mysql oracle gwt openjpa jmx yui google-guice android JBoss scwcd 5.0 scjp 1.5 scjp 1.6 scja scbcd 5.0

javabeat | advertise | about us | contact | useful resources
Copyright (2004 - 2013), JavaBeat