This is kind of hard to do in practice unless you’re really watching where you’re allocating memory. It’s very easy in Java to end up accidentally throwing a bunch of allocated memory on the heap without realizing it.
Fwiw, the JVM now has a noop garbage collector so this is easy enough to benchmark.