EHC ❯ Memory leak and thread-safety issue in CacheManager & Configuration
-
Bug
-
Status: Closed
-
1 Critical
-
Resolution: Fixed
-
ehcache-core
-
-
hsingh
-
Reporter: arauch
-
November 15, 2010
-
0
-
Watchers: 0
-
January 17, 2013
-
November 23, 2010
Description
Starting in 2.2.0, CacheManager.addCacheNoCheck() adds the new CacheConfiguration to the Configuration map, but nothing (that I can see) ever removes this entry. This (indirectly, see reference path below) creates a permanent hard reference to every cache created, preventing them from being garbage collected. Our application (LabKey Server, www.labkey.org) creates and removes many temporary caches, and this leak makes 2.2.0 and 2.3.0 unusable.
In addition, use of the Configuration.cacheConfigurations map (an ordinary HashMap) doesn’t look thread-safe.
Below is the path from CacheManager to one of our removed caches, copied from jhat:
–> net.sf.ehcache.CacheManager@0xd956708 (145 bytes) (field configuration) –> net.sf.ehcache.config.Configuration@0xd9b8440 (114 bytes) (field cacheConfigurations) –> java.util.HashMap@0xd9b8810 (64 bytes) (field table) –> [Ljava.util.HashMap$Entry;@0xf1d1340 (528 bytes) (Element 2 of [Ljava.util.HashMap$Entry;@0xf1d1340) –> java.util.HashMap$Entry@0xf559b50 (44 bytes) (field value) –> net.sf.ehcache.config.CacheConfiguration@0xf559c00 (217 bytes) (field listeners) –> java.util.concurrent.CopyOnWriteArraySet@0xf55a018 (24 bytes) (field al) –> java.util.concurrent.CopyOnWriteArrayList@0xf55a030 (32 bytes) (field array) –> [Ljava.lang.Object;@0xf55a098 (24 bytes) (Element 0 of [Ljava.lang.Object;@0xf55a098) –> net.sf.ehcache.store.compound.impl.MemoryOnlyStore@0xf55a0b8 (92 bytes) (field primary) –> net.sf.ehcache.store.compound.factories.CapacityLimitedInMemoryFactory@0xf55a1a8 (68 bytes) (field eventService) –> net.sf.ehcache.event.RegisteredEventListeners@0xf55a208 (80 bytes) (field cache) –> net.sf.ehcache.Cache@0xf55a2f0 (187 bytes)
Comments
Fiona OShea 2010-11-29
Himadri Singh 2010-12-15
CacheManagerTest covers the issue
Fix in branch ehcache-core-2.3.x and ehcache-core/trunk