Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is hard reference in java?

Tags:

java

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?

like image 547
satheesh.droid Avatar asked Jul 11 '11 11:07

satheesh.droid


People also ask

What are Java reference types?

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.

What is strong reference and weak reference in Java?

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.

What is soft reference and weak reference in Java?

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.

What is weak reference in Java example?

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.


2 Answers

Here are a couple of tutorials of hard (aka strong) and weak references in java

  • http://weblogs.java.net/blog/2006/05/04/understanding-weak-references
  • http://www.coderanch.com/t/433742/java/java/WeakReference-hard-reference-scope-JIT

Found by simple googling

like image 62
Armen Tsirunyan Avatar answered Oct 04 '22 23:10

Armen Tsirunyan


Hard references are normal references, i.e. variables, as opposed to subclasses of java.lang.ref.Reference, phantom, soft, and weak references.

like image 42
Christoffer Hammarström Avatar answered Oct 04 '22 23:10

Christoffer Hammarström