File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Soft Skills this week in the Jobs Discussion 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: 40052
    
  28
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: 24187
    
  34

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