This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Behaviour of WeakHashMap

 
Gopal Shah
Ranch Hand
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
Suppose we r running low of memory, then what happens to the mappings of WeakHashMap object. Are all the keys (mappings) removed or only few keys (equivalent to the amount of memory req.) are GC.
If later one is true, then on what basis the object for GC is chosen ? FIFO, LIFO or some other algo.
Thanks in advance.
Gopal Shah
 
Sumitro Palit
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think when garbage collection kicks in, its going to clear as many weak references (keys) it can, normally won't do it selectively like using a FIFO/LIFO algorithm. So if you are implementating a caching mechanism using a WeakHashMap dont rely on such behavior.
Checkout this article for details:
http://www.onjava.com/pub/a/onjava/2001/07/09/optimization.html
Cheers,
-ortimus
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic