Skip to content

References in java

May 13, 2010

Strong: The general object created is with strong reference
Weak Reference: GC will not take this reference as a strong one to uphold the object from GC. so we can get null sometimes – for this we can use WeakHashMap where entry removed if object as key removed.
Use the ReferenceQueue class to determine the objects removed to do cleanup.

Soft Reference: Will continue to keep object in memory as long as the environment (memory) permits.
Phantom Reference:Will always return null for object not existing – marked for gc. useful if you want to know the point at which object was marked for gc. and also for avoiding finalize for the objects.

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: