Recently, I have been working with a non-ML program that is very heavy on Java, and I feel your pain.
I can’t tell you if there is a reset of dynamically allocated memory based on one indisputable technical fact, but my personal experience tells me that if you are going to continue processing in the native R environment after working with Java, you probably should. It’s best to control what you can.
That's why:
The only time I ever ran out of memory (even working with flat MASSIVE files), I once used the JVM. This is not one time, it happened often.
It is even just reading and writing large excel files through XLConnect, which is controlled by Java; memory is quickly stuck. The failure seems to be in the way R and Java play with each other.
And, r does not automatically collect garbage the way you hope. It collects when the OS requests more memory, but everything can slow down long before this happens.
Also, R sees only objects in memory that it creates, and not those that it interprets, so your Java cube will be delayed without the knowledge of R. So if the JVM created it, R will not clear it if Java does not do it before not sleeping. And if the memory is selectively recycled, you may have fragmented memory gaps that greatly affect performance.
My personal approach was to create sets, variables, frames ... a subset just for what I need, and then rm() and gc() ... delete and force garbage collection.
Proceed to the next step and make a heavy lift. If I run a Java-based package, I will do this cleanup more often to keep the memory clean.
Once the Java process is done, I use detach(yourlibraryname) and gc() to clear everything.
If you adjusted the heaps, I would rewrite the redefinition here, reducing the allocation that you give to Javas dynamic memory, because R cannot return it if the Java virtual machine is still involved, but does not work as far as I can tell. Therefore, you must reset it and return R to use R. I think that ultimately it will benefit you with faster processing and less locks.
The best way to find out how this affects your system when you use it is to use the sys.time or proc.time function to see how long your script takes with or without forced garbage collection, seizures, squads and heap redistribution.
You can get a complete picture of how to do this here:
IDRE -UCLE proc.time functions
Hope this helps some!