How many bytes of memory does a java.util.Date object use?

后端 未结 7 2107
故里飘歌
故里飘歌 2020-12-10 12:15

I need to store a large amount of dates (potentially large enough that the amount of heap space used is a concern so please, no lectures on premature optimization), and I\'m

相关标签:
7条回答
  • 2020-12-10 12:47

    I tried a manual calculation based on the rules here: http://www.javamex.com/tutorials/memory/object_memory_usage.shtml and checking the source code of the Date object in Java 7 the memory usage.

    Object overhead: 8 bytes => 8 bytes
    + 1 long fastTime: 8 bytes => 16 bytes
    + 1 reference cdate: 4 bytes => 20 bytes
    Rounded up to nearest multiple of 8 => 24 bytes
    

    Maybe I'm missing something in the calculation or the tools that were used in other answers that gave a result of 32 were including the references to the dates themselves in the calculation?

    0 讨论(0)
提交回复
热议问题