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 JVM crash dump --  free objects.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "JVM crash dump --  free objects.." Watch "JVM crash dump --  free objects.." New topic
Author

JVM crash dump -- free objects..

Pavan Kumar
Greenhorn

Joined: Jun 08, 2005
Posts: 23
Hi All,

I am trying to get the data from a table and put the data for each record in a map and place them in an array list. The problem is that after sometime, the JVM is crashing as due to insufficient memory on the JVM Heap.. The code looks something like below.. I guess I should pull the resultMap initialization outside the loop and reuse it..

List lst = new ArrayList();

for(int i=0; i< 60000; i++){
Map resultMap = new HashMap();
resultMap.put("XXX", YYY);
resultMap.put("ZZZ", PPP);
lst.add(resultMap);
}

Change it to :

List lst = new ArrayList();
Map resultMap = new HashMap();

for(int i=0; i< 60000; i++){
resultMap.put("XXX", YYY);
resultMap.put("ZZZ", PPP);
lst.add(resultMap);
resultMap.removeAll();
}

Can anyone please suggest on this..
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Adding an object to a list adds a reference to that object. In your second version of the code, you'll have a list with 60,000 references to the same map, and that map will be empty. Not very useful.

In any case, if you're running out of heap space for your large data structure, then you can just use a bigger heap; check out the -XmxNNm command-line switch to the Java executable.


[Jess in Action][AskingGoodQuestions]
Pavan Kumar
Greenhorn

Joined: Jun 08, 2005
Posts: 23
Thank you Friedman for the reply..
Does this mean I have wait for the code to exit out of the function and the garbage collector to free all the 60,000 instances of the object before I can resuse them?? Here is one more question which I would like to ask you.. Once I place all the 60,000 records in an array list, I will be using that data to query another table to find any changes and if there changes, I need to update the first table with the changes.. I was calling a function which would perform the update and then close the resultset and statement objects.. Now my question is will it be better to call the function something like 30,000 times to do update or place those 30,000 records in an arraylist and call the function once to do the update 30,000 times.. I appreciate your help..

- Pavan.

Originally posted by Ernest Friedman-Hill:
Adding an object to a list adds a reference to that object. In your second version of the code, you'll have a list with 60,000 references to the same map, and that map will be empty. Not very useful.

In any case, if you're running out of heap space for your large data structure, then you can just use a bigger heap; check out the -XmxNNm command-line switch to the Java executable.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JVM crash dump -- free objects..