I was programming a neural network in which I save the data of the weights in one long txt
file and so to retrieve that data I used '|' to separate numbers and then added into an array before returning it.
Using this method my ram usage goes to 1500
MB and doesn't go away until the whole program ends but without it my ram usage goes to 700
.
I tried to close everything, maybe thinking one of my objects is a thread, but that didn't work either. Is there anything in my code that could be causing this ram usage
Here's the code :
public static int[] findDoub(String fileName) {
ArrayList<Integer> innt = new ArrayList<Integer>();
try {
File file = new File(fileName);
FileInputStream strem = new FileInputStream(file);
BufferedInputStream buff = new BufferedInputStream(strem);
int index = buff.read();
StringBuilder doubus = new StringBuilder("");
for (int i = 0; index != -1; i++) {
char a = (char) index;
if (i > 0) {
if (a != '|') {
doubus.append(a);
} else {
innt.add(Integer.valueOf(doubus.toString()));
doubus = new StringBuilder("");
}
}
index = buff.read();
}
buff.close();
strem.close();
buff = null;
strem = null;
} catch (IOException e) {
e.printStackTrace();
}
Runtime.getRuntime().gc();
int[] innnt = new int[innt.size()];
for (int i = 0; i < innnt.length; i++) {
innnt[i] = innt.get(i);
}
return innnt;
}