Is there a way of estimating (roughly) in memory object size from Serialized object size in Java
-
3[More or less similar here] (stackoverflow.com/questions/3983360/…)sudmong– sudmong2011-08-22 11:09:18 +00:00Commented Aug 22, 2011 at 11:09
-
possible duplicate of Estimate serialization size of objects?Ciro Santilli OurBigBook.com– Ciro Santilli OurBigBook.com2015-05-02 20:08:18 +00:00Commented May 2, 2015 at 20:08
2 Answers
The size in memory will be usually between half and double the serializable size. The most extreme example might be the Byte which is more than 80 bytes Serialized can be 16 bytes in memory.
You can use a profiler to tell you how much memory an object uses. Another way is to use a tool based on Instrumentation.getObjectSize(object)
You might find this interesting Getting the size of an Object
14 Comments
length. Most JVMs are 8-byte aligned so you need to round up to the next 8 bytes.A very nice Tool for this challenge: https://github.com/jbellis/jamm
From the readme.txt:
MemoryMeter is as accurate as java.lang.instrument.Instrumentation.getObjectSize, which only claims to provide "approximate" results, but in practice seems to work as expected.
MemoryMeter uses reflection to crawl the object graph for measureDeep. Reflection is slow: measuring a one-million object Cassandra Memtable (that is, 1 million children from MemoryMeter.countChildren) took about 5 seconds wall clock time.