You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AbstractApplicationEventMulticaster can leak classes [SPR-11606] #16229
in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug
This was discovered as part of the PR mentioned above, in the context of XD.
Basically, we create app contexts which have their own classloaders and can come and go. Those contexts (modules in XD terms) have a parent context that lives longer.
If event listeners are installed in the child context, listening for an event type that is loaded by the custom classloader, the parent context will still retain the types and hence the CL long after the child context has been torn down, preventing proper GC.
When an even is published in the child context, it is also propagated to the parent. The basic publish mechanism first retrieves the listeners that are eligible for that event and cache them if this has not been the case.
When your sample event is published, the cache of the parent is filled wit a reference to this child event. The problem, as you already mentioned is that ListenerCacheKey holds a reference to a Class and prevents a proper collection of the child context.
One way of fixing this issue would be to clear this cache when a child context is closed as some child-specific information may have been stored in that cache. I have tried that locally and it works as expected but I still need to figure out if that's the proper way to do it and where.
Creating your own ApplicationEventMulticaster won't buy you much: at best you could prevent a caching operation if the context in the event is not "your" context but that can prove to be very inefficient.
Fixed with an approach similar to #16145, checking cache safety of the event type and source type before adding them to the cache. To be available in the next 4.0.3 snapshot.
in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: bugA general bug
Activity
spring-projects-issues commentedon Mar 26, 2014
Stéphane Nicoll commented
When an even is published in the child context, it is also propagated to the parent. The basic publish mechanism first retrieves the listeners that are eligible for that event and cache them if this has not been the case.
When your sample event is published, the cache of the parent is filled wit a reference to this child event. The problem, as you already mentioned is that
ListenerCacheKeyholds a reference to aClassand prevents a proper collection of the child context.One way of fixing this issue would be to clear this cache when a child context is closed as some child-specific information may have been stored in that cache. I have tried that locally and it works as expected but I still need to figure out if that's the proper way to do it and where.
Creating your own
ApplicationEventMulticasterwon't buy you much: at best you could prevent a caching operation if the context in the event is not "your" context but that can prove to be very inefficient.spring-projects-issues commentedon Mar 26, 2014
Juergen Hoeller commented
Fixed with an approach similar to #16145, checking cache safety of the event type and source type before adding them to the cache. To be available in the next 4.0.3 snapshot.
Juergen