SCJP: Garbage Collection #Java Short Notes #SCJP

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

From: http://sitestree.com/?p=4863
Categories:Java Short Notes, SCJP
Tags:
Post Data:2009-03-10 13:59:45

Shop Online: https://www.ShopForSoul.com/
(Big Data, Cloud, Security, Machine Learning): Courses: http://Training.SitesTree.com
In Bengali: http://Bangla.SaLearningSchool.com
http://SitesTree.com
8112223 Canada Inc./JustEtc: http://JustEtc.net (Software/Web/Mobile/Big-Data/Machine Learning)
Shop Online: https://www.ShopForSoul.com/
Medium: https://medium.com/@SayedAhmedCanada

Leave a Reply