Heap memory and object memory

According to the article on Java memory and features:

"... The memory count is divided into two types: heap memory, which is the memory consumed by the application at runtime, and object memory, which is the memory allocated by various objects used in the program, such as integers and strings, etc. .... "

Do they mean stack memory when they say an object , or what do they mean? (confused, because if I'm not mistaken, objects are allocated on the heap in Java)

The second question is, if I just want to measure the total size of the heap and stack during the full execution of the program, which tool should I use? I looked through and tested the built-in Java Profiler in NetBeans 7.3.1 , as well as YourKit 12.0.6 , where I can check a bunch, but when it comes to examining "objects" and variables pushed onto the stack, I can't find a way!

To summarize, how can I determine what the paper describes:

  • Heap shared memory used
  • Used shared memory of objects

Thanks!

+4
source share
2 answers

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

+1
source

I think they had in mind a memory area designed to load classes and static data. I always called it not a bunch of memory. I am using VisualVM to measure memory usage. Accurate memory measurement is challenging, as usage fluctuates constantly when the garbage collector starts, classes load and unload, etc.

Graphs of memory usage over time are usually more useful for understanding and finding problems / memory usage.

http://visualvm.java.net/

0
source

Source: https://habr.com/ru/post/1497881/


All Articles