I have a problem when try to use hashtable with large data. I have a text file that contains over 111000 record, and when it reach 75000, outofmemory exception was thrown, so does anyone have any solution for this?
The problem happen at the line :
while ((text = reader.readLine())!= null);
and because of the java.lang.String <init> inside the readLine(), but I think the problem come from the hashtable too big to keep store data.
I tested it on my xperia Neo and it failed although it run quite good on another samsung device.
The object SoundUnit which I keep on hashtable has a structure below:
private String filename;
private int start;
private int end;
just above 3 field inside SoundUnit object.
Here is the piece of code I use to read data from text to store on hashtable:
reader = new BufferedReader(new InputStreamReader(new FileInputStream(unitSelectionFile), "UTF-8"));
String text=null;
do {
if (text.length() != 0) {
if (mainHash.get(text)==null)
mainHash.put(key, soundUnit);
}
} while ((text = reader.readLine())!= null);
Yes, most likely the hashtable is simply to large. I did a test on a Galaxy Nexus, which is a rather new phone, and it ran out of memory after 230k entries, with unique keys and values about 8 chars long. I would suggest to put your data in a database instead.
Your reader should not be an issue, since
BufferedReaderonly uses a small amount of memory.