java memory is a bit complicated. Your program runs inside jvm, jvm runs inside os, os uses the resources of your computer. When your program needs memory, jvm will see if it already requested some memory that is not currently in use, if there is not enough memory, jvm will ask for os and, if possible, get some memory.
From time to time, jvm will look for memory that is no longer in use and free it. Depending on the (huge) number of factors, jvm can also put that memory back into os so other programs can use it.
This means that at any given time, you have a certain amount of memory received by jvm from os, and a certain amount that jvm uses.
At any given point, jvm may refuse to receive more memory because it was patched up for this, or os may deprive jvm of access to more memory, either because it is instructed to do it again, or simply because there is no more free ram .
When you run your program on your computer, you probably don't give any restrictions to jvm, so you can use a lot of rams. When launched in Google applications, there may be restrictions imposed by jvm by Google operators, so the available meory may be less.
Runtime.freeMemory will tell you which part of the bar received by jvm from os is currently free.
When you allocate a large object, say one megabyte, jvm may require more bar for os, say 5 MB, resulting in freeMemory will be 4 MB more than before, which contradicts intuition. Allocating another MB is likely to reduce free memory as expected, but later jvm may decide to free some memory to thenos, and freeMemory is compressed again for no apparent reason.
Using totalMemory and maxMemory in combination with freeMemory, you can better understand your current limits and consumption.
To understand WHY you are consuming more bars than you expected, you should use a memory profiler. A simple but effective package is packaged with visualvm, a tool that is already installed using jdk. There you can see what ram uses in your program and why this memory cannot be restored by jvm.
(note that the jvm memory system is much more complicated than that, but I hope this simplification helps you understand more than the complete and complicated picture).