Few days ago I had a problem on one of the projects that I am working on, we observed that after a number of requests, ScriptEngine from Nashorn starts to work slower. Everything which I’m going to talk about is not a rocket science, there’s no clever and tricky tips, it’s just a straightforward explanation how you can find memory leaks.
I’m running project in a virtual box, so I started my services with JMX feature enabled. Just start your apps with following params:
Just enter your terminal and type
You should get following screen:
Add a remote connection, specify JMX port and connect.
You have to wait some time before retained memory will take place and you will be able to analyse it. It’s up to you how long to wait, in my case, it was enough to wait 4-5 hours.
Now go to Monitor section, press Heap Dump button and specify path where heap dump should be saved. In my case it was
Then copy it from remote server to your local pc.
Go to Eclipse MAT site and download latest version. Once it’s downloaded, unzip and launch it.
Then open heap dump, specify that you want to analyse it for memory leaks and that’s it. Wait for one minute and see the results.
In my case, it was the way Nashorn works, I have used a profiler to find the problem.