This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Error accessing ArrayList " Watch "Error accessing ArrayList " New topic
Author

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 occurs.how many element can the arraylist store? is it the integer.maxValue? But is it possible to store that much element with -XMS 1024 m?

thanks,
jeff
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36452
    
  15
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
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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: http://aspose.com/file-tools
 
subject: Error accessing ArrayList
 
Similar Threads
array subtraction
issue with stack
two dimension array
ArrayList vs Vector Size and Capacity difference ?
ArrayList