Description
Robert Cohen opened SPR-11520 and commented
I have a Spring Context hierarchy that is two levels where each node has it's own classloader. I load the child context using an XML bean definition and as an option, there may be a context:component-scan defined within the child context's XML to enable annotation style auto-wiring. When we have this component-scan, the child classloader is not garbage collected if the child context is closed. If we use XML for all of our bean definitions, then the classloader is collected properly.
The attached test project reproduces the leak consistently after creating/closing a child context about 318 times.
Using a profiler, I can see that the child classloader is being held due to child context Classes being left in the Parent's DefaultListableBeanFactory "allBeanNamesByType" variable:
/** Map of singleton and non-singleton bean names keyed by dependency type */
private final Map<Class<?>, String[]> allBeanNamesByType = new ConcurrentHashMap<Class<?>, String[]>(64);
They are added to the Parent DefaultListableBeanFactory allBeanNamesByType map by method DefaultListableBeanFactory. getBeanNamesForType(), however they are not removed when I close the context.
As the server is used an child contexts get redeployed, we eventually encounter OOM errors.
Affects: 3.2.8
Attachments:
- parent child leak.zip (2.23 MB)
Issue Links:
- AbstractApplicationEventMulticaster can leak classes [SPR-11606] #16229 AbstractApplicationEventMulticaster can leak classes
- Performance regression for custom autowireBean calls with many properties [SPR-11875] #16494 Performance regression for custom autowireBean calls with many properties
- Revise cache safety check to avoid performance regression in EAR packaged applications on WildFly [SPR-16714] #21255 Revise cache safety check to avoid performance regression in EAR packaged applications on WildFly
Backported to: 3.2.9
0 votes, 6 watchers