Actually, 16 bytes per Integer instance sounds reasonable to me. While I haven't made a deep study of this topic, I have had to learn a bit about it. I have a project that deals with terrain data which processes large data sets and requires the creation of multiple millions of objects at a time. The objects themselves are small, so the memory overhead is quite a substantial factor. To deal with that successfully, I had to do some
testing and investigation (including using the "Unsafe" API to inspect the bytes of objects, and watching the system process size to evaluate how large the JVM memory use grows during test runs). Here's what I've found:
In the HotSpot JVM for Windows, Java uses "compressed" object references which require only 4 bytes provided when running with a heap size of smaller than 32 gigabytes (some other JVM's require 16). For various reasons, all objects must be stored at memory addresses that are a multiple of 8 bytes (there's a long history of this going back to C/C++ structures). So when the JVM is running with a maximum memory space of fewer that 2^35 bytes, it simply divides the addresses by 8 before storing them and multiplies them by 8 before using them. So only 32 bits (4 bytes) are required for object references.
So, the JVM uses the following per object
8 bytes management (including object-synchronization overhead)
4 bytes reference to object's class
x bytes as required for member elements and to "pad" the object size out to a multiple of 8
In the case of Integer, that 'x' value would be 4 bytes to represent the integer value. Bringing the total up to 16. I strongly suspect that there's additional overhead for garbage collection and management, but I've looked at the process size for the JVM in my experiments and I think it's relatively small.
Okay, one other comment. One of the other posters asked you why you would care about this. While he has a point, I can think of a couple of circumstances where you might care very much. For example, if you're doing any kind of image processing you routinely deal with mega-pixel images. A Java int would be a fine representation for your pixel data in this case, but an Integer would be disastrous both in terms of memory
and performance. Similar principles would apply for any scientific application that deals with raster data or other large fields of regularly spaced samples. On the other hand, if you're implementing a user interface and using a ComboBoxModel model based on Integers, the size of the individual objects is trivial compared to everything else that's going on.
So I guess that, in most cases, if your application uses an appropriate data representation for the problem you are dealing with, Java will do a pretty good job of taking care of the memory considerations for you.
Gary
P.S. If you're interested, you can see the project where I've dealt with this stuff at
Tinfour