Sunday, April 10, 2011

What are the various types of references in Java ?

In Java the various types of references can be classified as follows

  • Strong Reference - The default reference, The garbage collector would not remove this strong reference

  • Soft Reference - The Java Garbage Collector would remove the soft reference when it is low for memory. These type of references are ideal for implementing your own cache.

  • Weak Reference - Weak references are the type of references which would be removed in the next cycle of Garbage Collection

  • Phantom References - Here the memory is never reclaimed though the Object would be finalized.

No comments:

Post a Comment