aspose file tools
The moose likes Java in General and the fly likes Memory Mgt: Giving memory from ArrayList back to VM? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Memory Mgt: Giving memory from ArrayList back to VM?" Watch "Memory Mgt: Giving memory from ArrayList back to VM?" New topic
Author

Memory Mgt: Giving memory from ArrayList back to VM?

R Jarman
Greenhorn

Joined: Feb 08, 2005
Posts: 27
I'm reading a ResultSet that gets 1.5 million rows. I put the data into an ArrayList of objects and then do some processing on it. Before the processing, I close the ResultSet. I then get a connection to a different DB server and write the data in the ArrayList out to this DB. I then need to do this process again only reading and processing a different ResultSet. The problem is when I start the second process, I get an out of memory error. I have adjusted the heap size on the VM to -Xmx1024m. I close my ResultSet. I also tried giving back the memory of the ArrayList by parsing it in reverse and doing a remove() for each element. I'm not sure if this works or if I'm depending on the garbage collection. Any ideas on how I can manage the memory better?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32830
    
    4
You ought not to need to remove anything from your List. Simply allowing the List to go out of scope will permit it to be cleared by the garbage collector. You should consider whether it is necessary to download al 15000000 values simultaneously.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That's a huge amount of data to keep in memory. As long as there are no references to the members of the array list, you should just be able to set the array list reference to null--but you never know what JDBC drivers are doing under the covers. I agree with Campbell--is it *really* necessary to process things like this? How big is each entry?
Bhagat Singh Rawat
Ranch Hand

Joined: Apr 04, 2009
Posts: 93
The workaround could be write data at file(secondary memory) and then read from file instead of keeping all the data in the Primary memory!!! :D


Brainbench Java 2.0 Fundamentals, J2EE 1.4
http://www.brainbench.com/transcript.jsp?pid=8192792
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Memory Mgt: Giving memory from ArrayList back to VM?
 
Similar Threads
Problems Processing Large ResultSet
NIO with large files
RAD 7.0 - V61 ResultSet reference is lost
JDBC Connections Freezing with Multiple Users Accessing DB
large resultset connection times out