Interesting Java classes
- WeakHashMap
Function: When accessing this map, all entries will be checked. If a key is not reachable (a concept in GC), the entry will be purged
Scenario: For example, we have an interface with add/remove methods. Mainly responsible for maintaining objects in HashMap within subclasses. The requirement is that the caller is responsible for adding/removing the object themselves. Forgetting the remove object may result in OOM. At this point, WeakHashMap can be used
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.
评论