BitSet using more memory than it should

163 views Asked by At

I was writing code to calculate prime numbers within which I was using a BitSet.
When executing:

int count = 1_500_000_000; // 1.5 billion
BitSet bitSet = new BitSet(count);

I get the exception java.lang.OutOfMemoryError: Java heap space


In my small world a BitSet that holds 1.5 billion entrys should roughly use:

1500000000 / 1024 / 1024 / 8 ~= 180 megabytes of memory.

Even though I'm creating a 32-Bit program these numbers should be nowhere near any limits should they?

0

There are 0 answers