File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Collection: Understanding WeakHashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collection: Understanding WeakHashMap" Watch "Collection: Understanding WeakHashMap" New topic

Collection: Understanding WeakHashMap

Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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?


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Yes. if the WeakHashMap contains the only reference to an object, then that object is eligible for GC.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
I agree. Here's the link:
subject: Collection: Understanding WeakHashMap
It's not a secret anymore!