-2

I need to measure memory usage some sort of method. I can get Heap and nonHeap Memory size using mxBean.getHeapMemoryUsage and mxBean.getNonHeapMemoryUsage.

My question is how do we caclulate memory usage in specific method execution? (Only consider HeapMemory or both)

trincot
  • 317,000
  • 35
  • 244
  • 286
Damith Ganegoda
  • 4,100
  • 6
  • 37
  • 46

1 Answers1

2

You should consider only HeapMemory and not NonHeapMemoryUsage. NonHeapMemory is where Java Virtual machine keeps method codes and classes byteCode stuffs.

Here is helpful link get OS-level system information

Note: you should consider stack memory as well, but that is very less compare to heap memory used by methods or class objects.

Community
  • 1
  • 1
Sushant Tambare
  • 526
  • 2
  • 9