[ https://issues.apache.org/jira/browse/IBATIS-562?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12656655#action_12656655 ]
Alan Charley commented on IBATIS-562: ------------------------------------- The hashMap does not enforce unique entries so 'replacing "A"' seems to generate two entries in the map. Removing the entry removes the hashMap entry preventing duplicates. Without this change HPJmeter points to HashMap as an estimated leak. Btw, I also added this code ... public void flush(CacheModel cacheModel) { int s = 0; s = cache.size(); cache.clear(); cache = Collections.synchronizedMap(new HashMap(s)); } So when the map gets flushed it creates a new map with size "s" This should improve performance over time for maps that have more than 10 entries. I'll submit this later as a "wish" ... > Memory cache using WEAK references can lead to memory leak > ---------------------------------------------------------- > > Key: IBATIS-562 > URL: https://issues.apache.org/jira/browse/IBATIS-562 > Project: iBatis for Java > Issue Type: Bug > Components: SQL Maps > Affects Versions: 2.3.4 > Environment: Hp NonStop H06.14 , NonStop Java 1.5.0_02 Ibatis build > 2.3.4.726 > Reporter: Alan Charley > > Caching objects in memory using WEAK references will lead to memory leaks > because GC can occur on object, yet cache memory still has reference to > object. Since the key is present in the hashmap but the object being cached > has been destroyed, value returns as null indicating a cache miss. Then the > object is cached again, and again, and again. This causes the haspmap to grow > until JVM crashes with out of memory. > Code snippet below from MemoryCacheController.java > public Object getObject(CacheModel cacheModel, Object key) { > Object value = null; > Object ref = cache.get(key); > if (ref != null) { > if (ref instanceof StrongReference) { > value = ((StrongReference) ref).get(); > } else if (ref instanceof SoftReference) { > value = ((SoftReference) ref).get(); > } else if (ref instanceof WeakReference) { > value = ((WeakReference) ref).get(); > } > } > /* AJC added this code to prevent memory leak if object key is in cached > list but value had been removed */ > if (value == null) { > if (ref != null) { > cache.remove(key); > } > } > /* end of code added */ > return value; > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.