You have 6e7 ribs. A regular object accepts 24 bytes (64-bit HotSpot), so 1.44e9 bytes are right there (1.5 GB). Now you present the most effective map you can imagine, adding only 67 links plus 67 Integer objects. This is another 2.4e8 bytes for refs and 1.44e9 bytes for Integer s: another 1.5 GB, the total number is now 3 GB, and this is the theoretical bottom line for your problem (modulo caching, see below).
Based on this, I suggest that you simply extend the Edge class with another int field. This will significantly reduce the amount of your memory.
If this is not an option, and:
- all your integers rarely exceed two digits,
- you try never to use
new Integer , but Integer.valueOf , autoboxing etc., - you are using Java 7,
You will automatically benefit from the built-in cache with a small amount. If integers take values ββfrom a wider range, but still with a lot of duplication, a custom cache is highly recommended.
Marko topolnik
source share