I hope you will all forgive me because this has been exhausted although I followed all the advices.
After the following examples, to check my own environment. I have done the following:
long heapSize = Runtime.getRuntime().totalMemory();
System.out.println(heapSize);
// Get maximum size of heap in bytes. The heap cannot grow beyond this size.
// Any attempt will result in an OutOfMemoryException.
long heapMaxSize = Runtime.getRuntime().maxMemory();
System.out.println(heapMaxSize);
// Get amount of free memory within the heap in bytes. This size will increase
// after garbage collection and decrease as new objects are created.
long heapFreeSize = Runtime.getRuntime().freeMemory();
System.out.println(heapFreeSize);
Which outputs is:
5177344
66650112
4437824
Currently, it looks like my heap cannot grow more than 6.6M right?
Now if I want to increase my maximum heap size, the command is adviced to be:
java -Xmx128m readFile.class
However, it keeps coming oout with an error:
Exception in thread "main" java.lang.NoClassDefFoundError: readFile/class
Where did that "main" come from? The only thing that I have done is that I have another class called myMain which calls this clss for test purposes.
The class which raised this heap problem was a class I was using to read files as in the bellow:
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class readFile
{
private ArrayList<String> dataFromFile= new ArrayList<String>();
....
public String readFile(String fileNameIn, String encoding) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(
new FileInputStream(fileNameIn), encoding));
buffer = new StringBuffer();
int i;
while((i = in.read()) != -1) buffer.append((char)i);
in.close();
return buffer.toString();
}
//return an array of each data read from file separated by a tab etc
public ArrayList<String> getRecords(String fileNameIn) throws IOException {
String s = this.readFile(fileNameIn);
String current;
Pattern p = Pattern.compile("[^\t\n]+|\t(?=\t)|\t$",
Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(s);
while(m.find()){
current = m.group(0).trim();
dataFromFile.add(current);
}//while
return dataFromFile;
}
....
}
Message was edited by:
McTaar
Message was edited by:
McTaar