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..
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..
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.