In the first post in the subject we pushed a whole lot of complexity away by stating that calculating shallow heap is easy – it consists of only the heap occupied by the object itself. But how do you calculate how much memory does the object “itself” require? Apparently there is a formula for it:
Shallow Heap Size = [reference to the class definition] + space for superclass fields + space for instance fields + [alignment]
If it does not seem too easy anymore, we have created a case study where this formula has been applied in practice to make it easier.