CachingMetadataReaderFactory does not release shared resource cache after context refresh [SPR-17527] #22059
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
status: backported
An issue that has been backported to maintenance branches
type: regression
A bug that is also a regression
Milestone
Philippe Julien opened SPR-17527 and commented
org.springframework.core.type.classreading.CachingMetadataReaderFactory.clearCache() was modified in Spring 5 to only clear the metaDataReaderCache of the LocalResourceCache instance type. When created with the constructor that takes a ResourceLoader as an argument, CachingMetadataReaderFactory will keep a strong reference on the Map that it got from the DefaultResourceLoader. This would be fine if DefaultResourceLoader.clearResourceCaches(), that is called after a context refresh, cleared the resourceCaches and the inner map that it contains, but this is not the case. So CachingMetadataReaderFactory.metaDataReaderCache remain in memory after context refresh.
In our application this increased the memory footprint by about 100mb after we updated to Spring 5.
A possible fix would be for CachingMetadataReaderFactory.clearCache() to set its metadataReaderCache to null if it's not an instance of LocalResourceCache.
Affects: 5.0.10, 5.1.2
Issue Links:
Referenced from: commits 23d1049, 262c702
Backported to: 5.0.11
The text was updated successfully, but these errors were encountered: