Clojure object size estimation
Some part of this post were adapted from a discussion on the clojure mailing list.
In a language such as Clojure that handles memory sharing of data structures transparently, it is a bit difficult to find a good measure of how much memory an object occupies. How does one count some substructure that is referenced by multiple objects?
A first option is to use
Vector(3) [Vector(3), Vector(2), List(2)]
A second option is to use the JVM's build-in memory tools to get a size estimate. As we will see below, this is I think a better estimate of how much an object actually increases the memory footprint.
One can clearly see the structural sharing if one runs the following cell twice.