In my code, which often runs on servers I do not control the configuration of, I have collection of users and each user has a byte[] array.
Sometimes these byte[] arrays are unique to the user. Often, though, there will be large numbers users with the exact same byte[] array.
I am trying to reduce the RAM consumption of my server.
I've tried turning my byte[] arrays into strings and interning them, but then I often run into PERM-GEN out-of-memory errors. I also see a significant performance degradation with the encoding/decoding when I want to access the byte[] array for a user, and I see much increased worse-case memory usage - presuambly strings are much larger than arrays.
How can I have a Set<SoftReference<byte[]>> lookup when Java arrays are not hashable and SoftReferences do not wrap the hash of the object the point at either. A Map<byte[],SoftReference<byte[]>> is obviously also defeating itself because the key is itself and prevents collection; and Set is internally implemented in terms of Mapanyway.
So how can I intern byte[] arrays?