Heap memory vs object memory

本小妞迷上赌 提交于 2019-12-05 15:26:25

Heap Memory : storage for Java objects. Say when you use new keyword to create an instance of a class.

Stack Memory : used to store local variables, method call, etc. JVM also can decide and use it to store certain objects for performance.

To get, total memory you used-

usedMemory = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();

You cannot get stack memory on runtime but you can start an app with predefined stack size which depends on your platform.

There's a non-heap memory which I think they defined as object memory which is used to store loaded classes..metadata, etc.

References:

MemoryMXBean

JConsole

I think they meant the area of memory reserved for loading classes and static data into. I've always referred to it as non-heap memory. I use VisualVM for measuring memory usage. Precisely measuring memory is challenging because usage is constantly fluctuating as the garbage collector is run, classes are loaded and unloaded, etc.

The graphs of memory usage over time are generally more useful for understanding and finding memory issues/usage.

http://visualvm.java.net/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!