`

Getting the Size of the Java Memory Heap

    博客分类:
  • java
阅读更多

The heap is the area in memory in which objects are created.

// Get current size of heap in bytes
long heapSize = Runtime.getRuntime().totalMemory();

// Get maximum size of heap in bytes. The heap cannot grow beyond this size.
// Any attempt will result in an OutOfMemoryException.
long heapMaxSize = Runtime.getRuntime().maxMemory();

// Get amount of free memory within the heap in bytes. This size will increase
// after garbage collection and decrease as new objects are created.
long heapFreeSize = Runtime.getRuntime().freeMemory();

分享到:
评论

相关推荐

    Eclipse Memory Analyzer中文使用说明(带书签)

    - 分析 Retained Size:关注对象的 retained size 而非 shallow size,因为 retained size 才真正反映了对象释放后能回收的内存。 - 理解 dominator tree:利用 dominator tree 分析内存结构,找出内存消耗的主要...

    The Busy Coders Guide to Android Development最终版2019

    The Table of Contents Each bullet shown below represents a chapter. Use the search field in the nav bar to search all of the CommonsWare books to see what they hold! Key Android Concepts Choosing ...

    CommonsWare.The.Busy.Coders.Guide.to.Android.Development.Version.8.2.2017

    The Android platform gives developers a fair bit of control while still supporting a familiar programming language. However, the frameworks, GUI widgets, and development model is different than any ...

    python3.6.5参考手册 chm

    PEP 486: Make the Python Launcher aware of virtual environments PEP 488: Elimination of PYO files PEP 489: Multi-phase extension module initialization Other Language Changes New Modules typing ...

    Debugging with GDB --2007年

    Getting In and Out of GDB . . . . . . . . . . . . . . . 11 2.1 Invoking GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 Choosing files . . . . . . . . . . ....

Global site tag (gtag.js) - Google Analytics