I have investigated this issue. While it is true that the memory is not freed with respect to the usage observed by the OS, it is freed within the Java VM.
Via the GraphBuilder I was able to perform the following steps with two products one after the other. I set the heap size to 12G.
To understand this you need to distinguish between the heap size and the used heap.
The heap size is what is observed by the OS process monitor. This more or less only increases over the runtime of the application. There are some configuration options to influence this but might go hand in hand with other shortcomings. See also the stackoverflow discussion.
The used heap changes over time and goes up and down.
For the above-mentioned runs the numbers were (in MB) after there completion:
run | used heap | heap size
1. | 1800 | 12000
2. | 2000 | 12000
I must confess that I’m not very sure anymore for the values of the second run. But they were of this magnitude.
These are just rough numbers. Right after the processing was completed the used heap was actually. But after triggering the garbage collection the value decreased and memory was freed for the next processing. triggering the garbage collection actually not necessary because it is performed automatically when the amount of free memory is low.
So I think there is not a real memory leak. Except for one issue I’ve observed. The above numbers were taken when the area was a new one and the DEM data needed to be downloaded. When the DEM was already locally available the used heap went down even further to ~150MB. So there might be a smaller memory leak in the DEM handling but this should be investigated separately.
As another example, I measured the memory for another use-case.
- The product has been opened
- 2 image views have been opened
- The views are closed again
- The product is closed too
As you can see, the used heap changes while the heap size only increases, except for the little decrease at the end.
So at the moment, I can’t see a huge memory leak. But I would agree that the overall memory consumption is too high for the above-used sample graph. To find out why this is happening needs more investigation. Each operation needs to be analysed. This is currently out of scope, unfortunately.
To trigger the garbage collection you can enable the performance toolbar.
Right-click on the toolbar and select Performance.
Now when you click on the graph the garbage collection is performed.