-
Notifications
You must be signed in to change notification settings - Fork 38.5k
memory leak in class org.springframework.core.ResolvableType [SPR-11394] #16021
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
Juergen Hoeller commented Phil, since ConcurrentReferenceHashMap is using soft references, it shouldn't really cause a memory leak... I guess we could switch to weak references there for more aggressive cleanup though? Juergen |
Phil Webb commented Yes,
|
Juergen Hoeller commented Hmm, the actual leak might be that ResolvableType refers to its own instances in the static cache there, so that the ResolvableType class itself can't get garbage-collected... in which case weak references would indeed help. However, with weak references, the entries would disappear almost immediately at the next GC run, since we use ResolvableType instances as keys here, and those typically aren't held as a strong reference anywhere... As a consequence, I wonder whether we should switch the cache to use the original Type as the key - a reference that is strongly held by the ClassLoader. Once the ClassLoader disappears, the cache would be cleared. Juergen |
Juergen Hoeller commented We need further feedback on how exactly a leak shows up there. According to our analysis, the GC should release those soft references once it actually requires memory, and we don't see anything on our side that would prevent that... Jeurgen |
David Geary commented We saw a problem in Spring XD M4 (which uses Spring 4.0.0.RC1) that may be related to this - running on Java 7 with the following options: -d64 -Xms2G -Xmx2G -XX:+UseG1GC It gets to the point where it doesn't actually throw out of memory errors, but starts to run very slowly as the majority of time is spent in garbage collection - From a heap dump we are seeing:
|
Charles O'Farrell commented Apologies if this is unrelated, but we just hit this in Atlassian Stash when a customer was running Java 1.7.0_51 (see #15959). The problem turned out that the equals method wasn't being called on proxied objects (in some cases) and resulted in the |
Holger Brandl commented I'm having a similar problem when using 4.1.0.RELEASE along with Tomcat8. When checking memory after undeployment of my webapp, many DAOs and Controller-classes are retained. I've tried to trace it down using YourKit and it seems to be related to this issue: As a workaround I'm using reflection now to clean it up:
Maybe this also helps to track down the problem: it turned out that the ResolvableType.cache contained around 10k entries including many duplicates of "java.lang.String=java.lang.String" or "boolean=boolean". |
Juergen Hoeller commented We're addressing #16880 - unnecessary duplicate entries - for tomorrow's Spring Framework 4.1.1 release. Please give it a try once available and let us know whether it improves the situation for you. Note that it is normal for the ResolvableType cache to contain entries with empty references even on shutdown: Those would usually be empty SoftReferences for which the garbage collector cleared the references - however, ResolvableType's cache will only purge those entries on next access, so they might still show up in a debugging session on shutdown. In any case, those are not a leak, just a temporary pre-cleanup situation. If a ClassLoader leak or out-of-memory scenario happens on repeated restart of an application, let us know, since that would clearly be a bug. Juergen |
Stéphane Nicoll commented I have tried to reproduce that problem and I couldn't. I can see those items in the cache but they are all marked as weak references. I can also see the kind of back trace in yourkit but they are not really surprising as the JVM is free to reclaim those any time it wants to. If you have enough memory it can just sit there. Do you have a concrete OutOfMemory and a way to reproduce this issue? That would be very helpful. Investigating this issue also helped to find a related issue (see #16880). It should be available in |
Holger Brandl commented
You're comments helped me to understand the problem better. Thank you for your help. |
Juergen Hoeller commented Alright, let's consider this as resolved for 4.1.1 for the time being. To be reopened if any problems remain. Juergen |
oaktree opened SPR-11394 and commented
Anayzling heap dump shows:
Affects: 4.0.1
Issue Links:
2 votes, 12 watchers
The text was updated successfully, but these errors were encountered: