-
Notifications
You must be signed in to change notification settings - Fork 38.5k
ConfigurationClassEnhancer prevents BeanFactory from being GCd [SPR-7901] #12556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Tommy Becker commented I've investigated this some more and found some more information. The use of static callbacks is not the root problem, as even the non-static callback mechanism uses ThreadLocals, and since the threads live for the lifetime of the JVM, the problem still exists. The root issue is the callbacks, regardless of how they are registered, need to be cleared when the context is destroyed. I've managed to get this to work in the interim by adding a |
Chris Beams commented Thanks for the detailed investigation and notes, Tommy. I'll take a look. |
Chris Beams commented
|
Tommy Becker commented Thanks for the fix Chris. Will try and take a look at it soon, although even with the workaround I described in place, we were still having OOM issues, causing me to open https://jira.springsource.org/browse/SPR-8008 So it will take a little more work for me to verify this specific fix... |
Chris Beams commented OK, I'll leave it in 'Waiting for Feedback', then. Verification will be much appreciated. These issues can be elusive, as you know too well :) Note that we're targeting M2 for release within the next 2-3 weeks, to give you a timeframe. |
Chris Beams commented
|
Tommy Becker commented
|
Chris Beams commented
If you're not using Maven, you can find the jars here: http://bit.ly/hfy4KI. Note that the only module affected by this change was spring-context, but other changes may require pulling down other dependent modules. The change was committed on March 14th, so anything after March 15th should include the change. Grab the latest to be safe, but it will also include the most dependecies on changes in other modules. |
Chris Beams commented Resolving as fixed for M2. The fix has been in for some time, and we've not heard further complaints on this front since. |
Uh oh!
There was an error while loading. Please reload this page.
Tommy Becker opened SPR-7901 and commented
We're experiencing OOM errors during unit test runs. We make fairly heavy use of Java based context configuration in our application as well as the tests. Upon investigation, I see that there are a number of ApplicationContext instances still referenced on the heap that should be collectable. It appears that the way the ConfigurationClassEnhancer is registering its BeanMethodInterceptor with the CGLIB generated subclass is the problem. In #10601, this was changed from Enhancer.registerCallbacks() to Enhancer.registerStaticCallbacks() to work around the fact that the former only applies the advice when method calls originate from the same thread that registered the callback. However using the static callback mechanism results in a static reference from the generated subclass to the interceptor, which in turn keeps a reference to the BeanFactory. So the BeanFactory is never eligible for GC, even after its been closed. Although problems running unit tests reveled the problem, we're most likely experiencing it at runtime as well since our application does close contexts and start new ones dynamically in response to some events.
As a potential fix, it would be nice if the BeanMethodInterceptor could receive a callback itself when the BeanFactory it references is closed, so it can then unregister itself from the CGLIB proxy. Alternatively, perhaps a WeakReference to the BeanFactory could be used from the interceptor.
Affects: 3.0.3
Attachments:
Issue Links:
@Configuration
classes cannot be garbage collected ("is duplicated by")@Configuration
classes cannot be garbage collectedReferenced from: commits d2faef4, 43676bd
5 votes, 3 watchers
The text was updated successfully, but these errors were encountered: