user1114496
user1114496

Reputation: 61

Heap memory vs object memory

According to a paper about Java memory and characteristics:

"... The memory score partitions into two types: heap memory, which is the memory consumed by the application during 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 the stack memory when they say object memory, or what do they mean? (confused since, if I am not wrong, objects are allocated in the heap in Java)

Second question, if I simply want to measure the total size of the heap and stack during a full program execution, what tool should I use? I have been looking around and tried out the built-in Java Profiler in NetBeans 7.3.1 and also YourKit 12.0.6, where I am able to inspect the heap but when it comes to studying "objects" and variables placed on the stack, I can not find a way!

To sum up, how do I measure what the paper is describing:

Thanks!

Upvotes: 4

Views: 942

Answers (2)

Saj
Saj

Reputation: 18702

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

Upvotes: 1

user2694688
user2694688

Reputation:

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/

Upvotes: 0

Related Questions