I have a Java process that needs to enlarge heap memory. To test how much I need to add I set the limit to a maximum of OS (128 GB) and let the process run while I analyze it with tools like VisualVM, jstatd, and all others.
I notice that the memory usage graph goes up from time to time until the OOM kills my process because it consumes all memory. Still, once I set the maximum heap to less – for example, 96GB, the java consumes less which makes the process run and not killed by OOM and the graph is pretty stable.
I think it is because the GC works more often but can not verify it.
also, what is the diff? if there are orphaned objects – why does the GC consider when to clean depending on memory?
I use G1GC.
Please help me to understand.