Why am I running out of heap space?

Situations like this often boil down to, “Check your assumptions”. I’ve had problems like this when, for example, something was screwed up in my logging, such that the more I looked at the problem, the worse things got.

Not saying that that’s exactly what is happening here, but it may be worth carefully examining the differences between the real system and the simple one. Given your memory-leak issue, something involved with reporting or suchlike wouldn’t be terribly surprising.

(Personally, I would probably systematically strip out pieces of the program until it no longer showed the leak, to basically binary-search for the problem.)

3 Likes

Quick review: I have a fast-time simulation that generates deconflicted aircraft trajectories and records them in an XML file. I also have a script that reads those trajectories from the XML file and verifies that they are free of conflicts.

As I explained earlier, the verification script has a memory leak that causes it to bog down and eventually run out of heap space. Inexplicably though, the fast-time simulation appears to have no such memory leak – even though it executes the same code and much more.

When I run the simulation for 720 trajectories, it runs to completion and then issues this warning:

[warn] In the last 20675 seconds, 38.608 (0.2%) were spent in GC. [Heap: 15.91GB free of 16
.00GB, max 16.00GB] Consider increasing the JVM heap using -Xmx or try a different collec
tor, e.g. -XX:+UseG1GC, for better performance.
[success] Total time: 20674 s (05:44:34.0), completed Jun 6, 2025, 10:23:27 PM

It tells me that 0.2% of the time was spent in GC. That seems low enough to not worry about, so why am I getting this warning? Any ideas about what is going on here?

That warning isn’t saying “your program is broken” or such, it’s saying “this is probably running slower than it would be with some adjusted parameters”.

It’s worth playing with them if you can – the pure amount of time spent in GC isn’t the whole story. Memory fragmentation and the like can make a real difference to that long runtime.

Yeah, but 0.2% of time spent in GC, and 15.91GB free of 16.00GB? If those figures are accurate, that does not seem like a problem to me. But are they accurate, and are they the max values, or are they just a snapshot at the end? They seem way too low.