• Post Reply Bookmark Topic Watch Topic
  • New Topic

Large hashtable | out of memory exception  RSS feed

 
Vishwas Khamboj
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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
 
Aneesh Vijendran
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • 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
 
R van Vliet
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • 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
 
Satya Maheshwari
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is what may work for you:
http://sourceforge.net/projects/phashmap/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!