Akshay
Akshay

Reputation: 832

Does Java create another strong reference instance from get() of WeakReference instance

For example,

WeakReference<Obj> weakObj = new WeakReference<>(obj);
Obj obj2 = weakObj.get()

In this example obj2 is strong reference type?

If yes means GC is not able to remove this reference until its parent get GCed?

Upvotes: 0

Views: 90

Answers (2)

Mirko
Mirko

Reputation: 1552

Your weakObj is a WeakReference, and yes, get() returns a standard reference.

Upvotes: 2

Alberto S.
Alberto S.

Reputation: 7649

Yes

Default references are strong references

You have some more information in this other question

Upvotes: 2

Related Questions