When I was studying about permgen, I came across the term hard reference. I don't know what is meant by hard reference. Can anyone explain or give me some tutorials about that please?
In Java there are four types of references differentiated on the way by which they are garbage collected. Strong References. Weak References. Soft References. Phantom References.
Strong - is a kind of reference, which makes the referenced object not eligible for GC. builder classes. eg - StringBuilder. Weak - is a reference which is eligible for GC. Soft - is a kind of reference whose object is eligible for GC until memory is avaiable.
A Soft reference is eligible for collection by garbage collector, but probably won't be collected until its memory is needed. i.e. garbage collects before OutOfMemoryError . A Weak reference is a reference that does not protect a referenced object from collection by GC.
A weakly referenced object is cleared by the Garbage Collector when it's weakly reachable. Weak reachability means that an object has neither strong nor soft references pointing to it. The object can be reached only by traversing a weak reference.
Here are a couple of tutorials of hard (aka strong) and weak references in java
Found by simple googling
Hard references are normal references, i.e. variables, as opposed to subclasses of java.lang.ref.Reference, phantom, soft, and weak references.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With