Heap memory : storage for Java objects. Let's say when you use a new keyword to instantiate a class.
Stack memory : used to store local variables, call a method, etc. The JVM can also solve and use it to store certain objects for performance.
To get the shared memory you used -
usedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
You cannot get the stack stack at runtime, but you can run the application with a predefined stack size, which depends on your platform.
There is heapless memory there, which I think they are defined as object memory, which is used to store loaded classes .. metadata, etc.
Literature:
MemoryMXBean
Jconsole
source share