If you ever found yourself in the need to implement a simple caching functionality in your Java programs, chances are that you at least considered using the WeakHashMap class as the cache. It turns out that the WeakHashMap makes for a terrible cache, and for two reasons. The first reason is that it uses weak references as the underlying memory management mechanism. The second reason is that the weak references are used for the keys and not for the values, which is what you would want. Reference classes and reachability To understand what the WeakHashMap is good for,
Read full article from Code Instructions: WeakHashMap is not a cache! Understanding WeakReference and SoftReference
No comments:
Post a Comment