How to test how many bytes an object reference use in Java?

前端 未结 4 1337
旧时难觅i
旧时难觅i 2020-12-18 00:50

I would like to test how many bytes an object reference use in the Java VM that I\'m using. Do you guys know how to test this?

Thanks!

4条回答
  •  萌比男神i
    2020-12-18 01:14

    It can differ from JVM to JVM but "Sizeof for Java" says

    You might recollect "Java Tip 130: Do You Know Your Data Size?" that described a technique based on creating a large number of identical class instances and carefully measuring the resulting increase in the JVM used heap size. When applicable, this idea works very well, and I will in fact use it to bootstrap the alternate approach in this article.

提交回复
热议问题