-
Notifications
You must be signed in to change notification settings - Fork 51
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
bugfix: added clearProperties(ClassLoader) method #215
Conversation
5a6f08c
to
1e2e5f9
Compare
You are going to need to provide a test case that demonstrates a memory leak. And once we have such a test case the fix will likely be to address the memory leak rather than adding a method that clears the cache. |
Hi, Mark, I modified the description to show exactly what's happening. Also uploaded screenshot from VisualVM. |
I'm still not seeing the evidence of a memory leak. Soft references are GC eligible. For a memory leak I'd expect to see a chain of hard references from the leaked object to a GC root. |
I have done a number of tests and the method in the PR is the minimum necessary to avoid the memory leak. |
@markt-asf Any thoughts please? Thank you |
There is no memory leak here (confirmed with a profiler). There is nothing to fix. Absent a test case demonstrating an actual memory leak, this PR and the associated issue will be closed. |
Hi, Mark, The memory leak is clearly demonstrated by the VisualVM screenshot and my comments above. This way, if I am right about this, the fix is already there :) Any help convincing Mark would be appreciated @smillidge @arjantijms @edburns @ivargrimstad |
Hi, Mark, @edburns would like me to produce a video with the memory leak. Thank you |
I would very much prefer a test case that demonstrates a leak - a leak being a hard reference to an object that isn't eligible for GC that should be eligible for GC. The information provided so far only shows a reference chain that contains a soft reference to the alleged leaking class. That is not a memory leak. Based on the information provided so far, I have been unable to recreate a memory leak via use of the BeanELResolver. My experience of videos (mainly in security vulnerability reports) is not good. The issues are:
You are of course free to provide a video if you wish and it will get looked at. However, I continue to believe the most effective way for you to demonstrate that there is an issue is to provide a test case that demonstrates the leak. I appreciate that creating unit tests for memory leaks is not always easy. The simplest possible web application (with source code) that demonstrates a leak that can be observed in a profiler would be sufficient. Given that I don't see how you can provide a video without first writing such a test case, my recommendation continues to be "provide the test case". Further: The proposed fixed is highly unlikely to be applied in any circumstances. Absent evidence of a memory leak, cruft is not going to be added to the API "just in case". If evidence of a memory leak is provided, then the fix is almost certainly going to be to fix the actual leak - not to provide a hack to work-around the leak. |
@markt-asf Would a Java process memory dump (e.g. hprof file) help demonstrate the leak? I personally prefer a memory dump over a picture or a video. |
@markt-asf Looks like you have tried to reproduce the memory leak yourself. Can you put that code up so I can take a look? Maybe I can modify it to demo the leak rather than start from scratch? |
Also, you claim that all references are soft. |
Because I have read the code - particularly the The test code I have been using:
|
…e ClassLoader leaks
ec45aee
to
e64af6b
Compare
Looking at your test, I can see why you would think it isn't a leak. The test above introduces memory pressure before forcing However, this is not a realistic situation, as memory pressure usually happens after the
However, I'd like to keep this PR open until the The risk of |
This PR really needs to be closed and this discussion moved to the issue. It does seem unlikely to me that there would be enough bean usage to cause notable memory usage, then some other activity that triggers GC and then no further bean usage until a OOME occurs. Unlikely, but I guess it is possible. I do wonder if some other memory leak was at play as well. There are a couple of options here. The simplest may be to switch using class name rather than class as the key. That would reduce the impact of what was left behind before cleanup() is called. Switching to a WeakReference based cache of some form is probably the better solution although it is higher risk. The Tomcat implementation has been used successfully since Java EE 5 but I'd need to check on where it originated. I know I didn't write it so I can't just copy it. |
I’ll make another PR with WeakReference as the change should be trivial |
The bean usage isn't the issue. The issue is that stale beans from undeployed applications drag in their ClassLoaders thus creating a huge leak. Even before that point, GC and memory thrashing occurs because there is a lot of uncollectable classes and garbage remaining. What I am describing above is not a hypothetical. It has been observed and recorded via JFR, VisualVM, JMC, etc. Solution is this PR is also not a hypothetical. With his applied, the OOM/GC thrashing issues are gone. Also observed by JFR/JMC/VisualVM
This will not work, because the cached bean (map value) contains a reference to application's object, which in turn will refer to it's ClassLoader, preventing it from being cleaned up. |
Superseded by #248 |
to BeanELResolver to help remove ClassLoader leaks
fixes #214
Relates to payara/Payara#6677