• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Memory Mgt: Giving memory from ArrayList back to VM?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic