Well, the first thing you should know is that the amount of memory you can allocate does not depend on how much RAM you have. The OS manages virtual memory, and any allocation is performed in virtual memory. Then the pieces are unloaded into the RAM / Disk OS. You have no control over this. You might think that you allocate 5 MB in RAM, but it depends on the OS to support it in RAM or to get it from your disk into your program when you need it. On Windows 32 bit, you have 2 GB in user space to work with (the rest is used by the kernel). In 64 bit OS, this number is much larger.
However, just because you have 2 GB of user space that you can allocate (in a 32-bit OS or more in the 64-bit version), this does not mean that you can always allocate a large piece, because for memory allocation contiguous blocks of memory are required. Thus, memory fragmentation can be a problem.
Third, the JVM limits the amount of memory that you can allocate. Therefore, you need to increase them using the -Xms -Xmx parameters that limit the heap size.
Other than these comments, I really have no solution for you.
source share