If I use the Runtime class (freeMemory(), totalMemory(), and gc()), then it gives me memory above MB (i.e. 1,000,000 bytes).
But if I run the same code on any online compiler, then they show memory used in KB (i.e. 1000 bytes). This is a huge difference.
This means Runtime does not show the actual memory used by the program.
I need to calculate actual memory used by the program. What is the way these online compilers use to calculate memory used by the program?