• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

What is Weak Reference

 
Ranch Hand
Posts: 45
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi All,
I was going through many links on Weak Reference,Weak HashMap.
Still iam not clear.So, I have chosen this 2 way communication.
Can anybody explain me?

Thanks.

Regards
Senthil Kumar Sekar
 
Marshal
Posts: 80269
430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are several kinds of reference, the commonest being strong. This means that an object is always “reachable” until the reference is broken, and that object cannot be deleted by the garbage collector.
There are at least two other kinds (weak and phantom). What they mean is that the object can be garbage collected, provided it has no strong references remaining. Have you found the package summary?
It appears that objects which cease to be strongly reachable are put into a queue to be deleted; when they are removed from the queue, their memory can be reclaimed because they are no longer reachable.

I am sure other people will know more about this than me.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically Weak References are one way of controlling object's garbage collection.

When an object is only reachable through Weak reference (which means object is neither strongly reachable nor softly reachable), then it becomes eligible for GC. During the run of GC, this object will be marked and garbage collected.

In case of WeakHashMap, keys are referenced through Weak references. When a key is not being used or it is not strongly reachable, then in next run of GC, these keys will be garbage collected and hence mapping entry will be removed from the hashmap.
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic