File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Error accessing ArrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Error accessing ArrayList " Watch "Error accessing ArrayList " New topic

Error accessing ArrayList

jeff rusty
Ranch Hand

Joined: Nov 07, 2006
Posts: 109
Hi All,

I am getting out of memory when i try to add elements in arrayList and here is what i do
I have a to identify eligble scores between a range of values and all the eligible scores should be stored in database so i am trying to run a
'for loop' from the start range till the end range to find out the eligible score between those range and adding it to a list.
The maximum range is between 10000000 - 99999999.
After adding '2362202 ' elements to the arraylist outofmemory many element can the arraylist store? is it the integer.maxValue? But is it possible to store that much element with -XMS 1024 m?

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46362
I tried once for entertainment purposes and managed to squeeze 6,000,000 objects into an ArrayList before getting the OutOfMemoryError, but how many scores do you actually need? Do you really have to squeeze 90,000,000 of them into the List? Reading your post makes me think there must be an easier way to do it . . .
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

2,362,202 objects is a pretty big arraylist, but the limit is Integer.MAX_VALUE, which is over 2 billion, so you've got a way to go.

You don't say what kind of objects you're storing in the arraylist, so we can't compute exactly how many fit into what sized heap, but in any case, yes, using -XmxNNm will let you use a larger heap and store more objects.

Now, finally, I really can't imagine what you could possibly be coding that would require you to create this long list of objects. Can you explain it a bit more? I'm pretty sure we could come up with something that would require far less memory. For example, a simple array of primitives would use far less memory than an ArrayList of objects; or a Map that matched only the indices with non-zero counts to their counts.

[Jess in Action][AskingGoodQuestions]
I agree. Here's the link:
subject: Error accessing ArrayList
jQuery in Action, 3rd edition