Types Of References In Java : Strong, Soft, Weak And Phantom
In this video we will learn Types Of References In Java : Strong, Soft, Weak And Phantom using a demo project
One of the beauty of the Java language is that it doesn’t put burden of memory management on the programmers. Java automatically manages the memory on the behalf of the programmers. Java programmers need not to worry about freeing the memory after the objects are no more required. Garbage Collector Thread does this for you. This thread is responsible for sweeping out unwanted objects from the memory. But, you have no control over garbage collector thread. You can’t make it to run whenever you want. It is up to JVM which decides when to run garbage collector thread. But, with the introduction of java.lang.ref classes, you can have little control over when your objects will be garbage collected.
Depending upon how objects are garbage collected, references to those objects in java are grouped into 4 types. They are,
1) Strong References
2) Soft References
3) Weak References
4) Phantom References
Below is the GitHub link to download source:
https://github.com/kishanjavatrainer/...