• 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

Large hashtable | out of memory exception

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

We are storing large number of objects(upto 5000) in a hashmap / hashtable resulting in out of memory error.
It is a requirement to store these many objects using a hashmap / hashtable as the records have to be displayed at one go. Is there a way to use these collections and avoid out of memory error.

Thanks
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Vishwas,

I am not sure, what kind of data are you storing in the hashtable. Anyhow it's not a good idea, if your idea is to store them all in a go inside teh hashmap. Or if it is to be displayed why not impliment some pagination ?

Why don't you try using Weakrefernce?

http://java.sun.com/j2se/1.4.2/docs/api/java/util/WeakHashMap.html

Cheers
Aneesh
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Aneesh Vijendran wrote:Hi Vishwas,

I am not sure, what kind of data are you storing in the hashtable. Anyhow it's not a good idea, if your idea is to store them all in a go inside teh hashmap. Or if it is to be displayed why not impliment some pagination ?

Why don't you try using Weakrefernce?

http://java.sun.com/j2se/1.4.2/docs/api/java/util/WeakHashMap.html

Cheers
Aneesh



I don't think a WeakReference is a solution to the problem unless keys are often discarded. Also, for 5000 objects to cause an OOM error those objects need to be quite big. You can start by using the -Xmx JVM command line parameter to increase your app's heap size. If that is not possible you'll have to explore ways to make the objects you are storing use less memory. The HashMap itself is not the issue with so few objects actually being mapped. If you cannot make your objects use less memory and they are also stored somewhere else (database, disk) consider using lazy loading (load the object when the data is retrieved, dump the object if more than X other more recently requested objects are being cached, etc.).

Remon
 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is what may work for you:
http://sourceforge.net/projects/phashmap/
 
reply
    Bookmark Topic Watch Topic
  • New Topic