Create a heapdump and check it with some analyzer (e.g. Eclipse MAT). That provides some insight of where that memory goes.
Since BitSets are objects and they contain values as well, you'll probably see the following (I bet I forgot something but you should get what I mean):
- for each BitSet you have a 8-byte reference (assuming you're using a 64-bit JVM)
- each BitSet contains a reference to a long[] array with one element, that's another 20 bytes (8 for the reference, 8 for the single value in the array, 4 for the length field of the array)
- each BitSet contains a boolean and an int, that's another 5 bytes.
Summing that up you get 33 bytes per BitSet (I'm sure I forgot something) and 25.000.000 * 33 bytes = 825000000 bytes (or around 786 MB).
25 million bits alone would need around 3 MB (e.g. if you'd create a BitSet that large).
As you can see, a BitSet containing only one bit is a huge waste of memory. If you can't use a single BitSet (I wouldn't see a reason for that though) you'd probably better off with a boolean array with a size of 25 million. That would still need around 95MB though.