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
Cglib2AopProxy weak reference causes perm space to fill up [SPR-4004] #8684
after upgrading to 2.0.7 i started getting a bunch of out of memory errors in my perm space. i think it has something to do with cglib proxies.
my method to create proxied objects:
public static Object create(Object obj) {
Advisor advisor = new DefaultPointcutAdvisor(VERSIONING_POINTCUT, new VersioningAdvice());
ProxyFactory pf = new ProxyFactory(obj);
pf.setProxyTargetClass(true);
pf.setOptimize(true);
pf.addAdvisor(advisor);
pf.setFrozen(true);
return pf.getProxy();
}
obj is a class, so cglib is used to create the proxy, which means it will generate a new subclass that handles the proxying. cglib uses Cglib2AopProxy$ProxyCallbackFilter as part of a key to a map that holds the generated classes so it doesn't have to regenerate a new class each time.
this worked in 2.0.6, but in 2.0.7 ProxyCallbackFilter uses a WeakReference to hold the advised object, which in my case is pf from the method above. once this method is complete, there are no strong reference to pf anymore, so after the next garbage collection the WeakReference will be cleared.
Cglib2AopProxy$ProxyCallbackFilter.equals uses the advised object (line 861), so after a garbage collection, two ProxyCallbackFilters that should have been equal are no longer because one of the advised references has been cleared.
this causes cglib to generate another class. so after every garbage collection, cglib will generate a new class, which will eventually lead to out of memory errors.
i have a feeling that my way of using ProxyFactory is not the best approach, but i'm not sure what other way to achieve this same behavior (other than using aspectj weaving, which i'd rather not do).
This is a side effect of the fix for #8302 which claimed a memory leak through holding a strong reference to the Advised object in ProxyCallbackFilter there... Any suggestions on how we could resolve this, satisfying both requirements?
i think the problem is that the ProxyCallbackFilter only needs access to the advisors and the class of the target source, not the actual target source itself. but since it maintains a reference to the target source, you get the memory leak in #8302 because cglib caches the ProxyCallbackFilter.
so if there is some way to have the ProxyCallbackFilter not keep a reference to the target source but without using a weak reference, then both problems should be solved.
i think the options are 1) to detach the target source (but keep a reference to its class) from the original AdvisedSupport, 2) clone the AdvisedSupport, but use a special TargetSource that only keeps a reference to the class of the object
I've fixed this through cloning the AdvisedSupport into a configuration-only copy, replacing the active TargetSource with an EmptyTargetSource that indicates the same target class (and same static/dynamic flag). This configuration-only copy is now held in a strong reference again, which shouldn't cause a problem with garbage collection anymore.
Activity
spring-projects-issues commentedon Nov 4, 2007
Juergen Hoeller commented
This is a side effect of the fix for #8302 which claimed a memory leak through holding a strong reference to the Advised object in ProxyCallbackFilter there... Any suggestions on how we could resolve this, satisfying both requirements?
Juergen
spring-projects-issues commentedon Nov 5, 2007
Alex Burgel commented
i think the problem is that the ProxyCallbackFilter only needs access to the advisors and the class of the target source, not the actual target source itself. but since it maintains a reference to the target source, you get the memory leak in #8302 because cglib caches the ProxyCallbackFilter.
so if there is some way to have the ProxyCallbackFilter not keep a reference to the target source but without using a weak reference, then both problems should be solved.
i think the options are 1) to detach the target source (but keep a reference to its class) from the original AdvisedSupport, 2) clone the AdvisedSupport, but use a special TargetSource that only keeps a reference to the class of the object
neither option seems all that satisfying though.
spring-projects-issues commentedon Nov 9, 2007
Juergen Hoeller commented
I've fixed this through cloning the AdvisedSupport into a configuration-only copy, replacing the active TargetSource with an EmptyTargetSource that indicates the same target class (and same static/dynamic flag). This configuration-only copy is now held in a strong reference again, which shouldn't cause a problem with garbage collection anymore.
Juergen
spring-projects-issues commentedon Nov 9, 2007
Alex Burgel commented
this fix works for me (using snapshot spring-framework-2.0.8-20071109-128)
thank you!