2

Can someone explain the difference between on-heap memory and off-heap memory?Does the off-heap memory show on the JVM memory size?Are the off-heap all pointers?

Shellong
  • 317
  • 1
  • 10

1 Answers1

3

All memory is native memory, however the JVM manages and record memory in it's JVM heap (not the same as the native heap)

Offheap is a Java term for memory not managed directly. However, it can be managed indirectly using direct ByteBuffer(s) as proxy objects for raw native memory.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • 1
    What does "not managed directly" mean?Does this mean that kind of object is not managed by the JVM?Is that just a pointer in JVM? – Shellong Aug 30 '18 at 12:02
  • @XiaolongZhou it's just a 64-bit `long` value which happens to be the address of some memory. – Peter Lawrey Aug 30 '18 at 16:30
  • Does the memory occupy the JVM memory?Or just the 64-bit long value is in the JVM, the pointed object is out of the range of JVM?Thanks! – Shellong Sep 02 '18 at 14:52
  • @XiaolongZhou off heap memory is still part of the memory of the process so from the OS point of view it is no different however it is not part of the normal areas the JVM uses. – Peter Lawrey Sep 02 '18 at 15:41