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
I use the method Injector.createChildInjector(...) to create many injectors with different configurations in my application. Each of those injectors is only used for a short period of time and then garbage collected.
Now it seems that for each injector an own set of fast classes is created for each SingleMethodInjector and others. For an example look at:
These fast classes (or at least meta data about them) are kept within a global map.
The Eclipse Memory Analyzer classifies this as a leak suspect:
One instance of "java.util.HashSet" loaded by "<system class loader>" occupies 671,209,552 (79.21%) bytes.
The instance is referenced by com.google.inject.internal.cglib.core.$AbstractClassGenerator$1 @ 0xfff4c7a0 ,
loaded by "com.google.inject". The memory is accumulated in one instance of "java.util.HashMap$Node[]" loaded by "<system class loader>".
I think it should be possible for Guice to share the fast classes between different injectors.
These are my findings after digging into the problem:
If then a Guice injector is gc'ed and a new one is created the fast classes are regenerated and their names are added to the class name cache. Hence the class name cache grows over time ...
Proposed fix: Switch to CGLIB 3.2.4
kenwenzel
changed the title
Memory leak and performance problem due to CGLIB fast classes
Memory leak due to CGLIB 3.2.0 fast classes
Oct 4, 2016
I use the method Injector.createChildInjector(...) to create many injectors with different configurations in my application. Each of those injectors is only used for a short period of time and then garbage collected.
Now it seems that for each injector an own set of fast classes is created for each SingleMethodInjector and others. For an example look at:
guice/core/src/com/google/inject/internal/SingleMethodInjector.java
Line 46 in f905d59
These fast classes (or at least meta data about them) are kept within a global map.
The Eclipse Memory Analyzer classifies this as a leak suspect:
I think it should be possible for Guice to share the fast classes between different injectors.
These are my findings after digging into the problem:
https://github.com/google/guice/blob/master/core/src/com/google/inject/internal/BytecodeGen.java#L245
My proposed fix:
https://github.com/google/guice/blob/master/core/src/com/google/inject/internal/BytecodeGen.java#L245
The text was updated successfully, but these errors were encountered: