Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Collection: Understanding WeakHashMap

 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the following example am I correct in saying that the assertion can fail,
because the WeakHashMap referenced by m2 could lose its contents, if there is some massive garbage collection taking place?

Thanks
-Barry
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. if the WeakHashMap contains the only reference to an object, then that object is eligible for GC.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic