Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java array memory usage

807600Sep 13 2007 — edited Sep 16 2007
I have a java program which unfortunately uses a large array of integers [4,100,000][2][2][5]. It declares this at program load and fills it with values shortly after. Just doing a bit of maths on this I calculate it to be 4 (32 bit int) * 4,100,000 * 2 * 2 * 5 = 328,000,000 or 328 mb.

I understand the language will use some extra memory for pointers and what ever else but I set the jvm to have 512mb of space and it uses all of it and runs into the out of memory error (if I write the values to a file instead it only uses about 6mb of memory). I tried it at 768mb (bearing in mind the computer only has 1GB) and it just seemed to be trying to declare memory all the time not doing any processing. I would use the file output but I need to do a recursive search over all the array so it would be very slow unless I have all data in memory.

Is it common to have memory usage of somewhere around double what I calculated to be the array memory requirement? surely not
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 14 2007
Added on Sep 13 2007
1 comment
551 views