I have a program in which I want to allocate the largest array possible. Is there a way in Java to query the VM to find out what that is? If so, how can I do it?
My latest attempt at getting the information was trial and error: I started trying to allocate the array with size Integer.MAX_VALUE and kept decrementing the size by 1 until the allocation was successful. But, it's taking a very long time; apparently the actual maximum is nowhere near the theoretical limit. I did establish that it's at least Integer.MAX_VALUE + 1. Come to think of it, it's at least 1.25 billion bytes.