Skip to content
loading...
markdown guide
 

You can use a profiler to inspect the JVM at run time.

  1. jmap is a free basic CLI tool you can use to inspect a JVM. You can dump the heap, monitor live heap memory and get a simple histogram of objects using this tool.

  2. jconsole is an upgrade to jmap with a GUI and more options.

  3. VisualVM is a great free tool with way more options.

All the above tools are shipped free with a JDK distribution. You can find all of them in <JDK>/bin directory.

  1. Also, you can use something heavyweight, like JProfiler as well.

You can use all these tools to connect to a running JVM and inspect the internals.

 

I'm checking out those as we speak, thank you very much!

 

Are you running it with any memory args like -Xmx ?

 

No I actually didn't, would that be the problem?

I removed them because I wanted to see if the little app was stable, then I came across said memory leak

 

I would try setting a max heap and see how that affects it. I can’t remember exactly what the calculation is but the JVM sets its default memory settings based on the overall system memory. If it’s assuming that it has a lot of memory available to it, it may allow the heap to grow without garbage collecting it. So, could be if you constrain the heap some more, the JVM will perform more garbage collection and keep the overall usage lower.

But, like other people are saying, your best window into what’s going on memory-wise is to take heap dumps and analyze them with a memory analyzer (MAT is a good free one that does leak suspect reports).

I think this would be your best option. Restrict max heap size an check if your app runs into an OutOfMemoryError. If that happens, use one of the mentioned tools to analyse your heap (take snapshots of your heap at different points in time, see what objects might accumulate).
But first, I'd also recommend to verify there's a memory issue

I did it yesterday, and ran into a memory error (not sure which), logs said the JVM killed the child or something... I should've saved that log I'm sorry

But I do am working on it, already taking a course on JVM memory :)

 

You'll want to use a tool like JavaMelody or JProfiler to be able to work out what's going on inside the JVM. You may want to look at taking a Heap Dump and analysing it; JProfiler has a pretty good Heap Walker which will allow you to sort objects by size or the number of instances, and most likely your top object here is the leak.

 
 
 

I forgot to give an update!

I wasn't able to edit it because most of the code was from work, so I made a quick project from scratch with nothing but the API and that one was working fine, therefore I had nothing to show you :(

But I'm already working out the problem based on the suggestions given

 

Will do tomorrow, I need to remove a couple things from work, I will reply to you again tomorrow

Classic DEV Post from Jul 20 '19

What Makes You a Great Programmer on The Team?

Majority of software developers are aspired to be not only a competent professional but also a great one.

Jashua profile image
I like chubby dogs