Memory not released after ProductIO.writeProduct and Product.dispose

I have an application that calls to some operators in a chain and writes the result.

After running ProductIO.writeProduct and Product.dispose() I would expect to see how memory consumption is decreased. However, it stays high and eventually gives a “Java Heap Error” (while writing other results).

Should this be reported as a bug?

Thank you

Any idea why this happens? I would expect the memory consumption to drop after disposing the Product. Am I wrong?

Yes. Actually, the memory consumption should go down. But not necessarily immediately. It also depends which kind of product you are using. The readers are differently implemented and this can cause different behaviour. Are you using Sentinel-1 data?

Yes, I use Sentinel-1 data.
I understand that the GC is responsible of collecting disposed objects. The problem is that under this scenario is impossible with my machine to call to ProductIO.writeProduct twice in the same application due to Java Heap Space Error (even if I push it to the limits of my macine).

In case it should be exptected, any idea how could I minimize this problem?

Thanks

How much memory does your system have? For some S1 processing chains, you should have at least 16GB.
What you can try is to enable the file cache for Sentinel-1 data.
When opening the options dialogue you can enable it on the S1TBX tab.
You can also create a file s1tbx.properties in <USER_HOME>/.snap/etc.
It should contain the following line:

s1tbx.readers.useFileCache=true