There is no method like "getMemory()" in Runtime class.
What you need is max memory allocated to JVM and find it using "maxMemory()" method, and then assign this max memory to array, you'll get OutOfMemory exception.
Ya its throwing error but when we use size less than maxMemory() ie 666501109 also its throwing error we are not getting the exact value of the size limit please give me the exact number(maximum size) that the array will not throw error up to that value
Arrays are non-negative integer indexed , so maximum array size you can access would be Integer.MAX_VALUE/2. The other thing is how big array you can create. It depends on the maximum memory available to your VM and the content type of the array. Each array element has its size, eg. byte = 1 byte, int = 4 bytes, Object reference = 4 bytes (on a 32 bit system). So if you have 1 MB memory available on your machine, you could allocate an array of byte[1024 * 1024] or Object[256 * 1024]. Answering your question - you can allocate an array of size (maximum available memory / size of array item).
Adam Michalik wrote:
Object reference = 4 bytes (on a 32 bit system)
I think its 8 bytes right for 32 bit system and 16 bytes for 64 bit system
After some research, I'm not so sure it is explicitly determined. See the other thread.
On the other hand, on a 32 bit system, a memory pointer takes 4 bytes, so I don't know if it was reasonable to have 8 byte references... What's more, an 8-byte reference would not fit into a 32-bit processor register, which in turn would be slowing down object reference resolution. Do you have any more info on usage of 8-byte references on a 32-bit system?
This one time, at bandcamp, I had relations with a tiny ad.