There are a huge number of service messages related to Multimap . Least:
- Each key and value is an
Integer object that (at least) doubles the storage requirements of each int value. - Each unique key value in a
HashMultimap is associated with a Collection values ββ(according to the source , Collection is a Hashset ). - Each
Hashset is created with a default space of 8 values.
Thus, each key / value pair requires (at least) an order of magnitude more space than you might expect for two int values. (Somewhat less when several values ββare stored under the same key.) I would expect 10 million key / value pairs to take, possibly 400 MB.
Although you have a 2.5 GB heap, I would not be surprised if that were not enough. The above estimate, I think, is on the low side. In addition, it only takes into account how much is needed to save the map after its creation. As the map grows, the table needs to be redistributed and rephrased, which temporarily doubles the amount of space used. Finally, all of this assumes that int values ββand object references require 4 bytes. If the JVM uses 64-bit addressing, the byte counter is probably doubled.
Ted hopp
source share