开发者

Java OutOfMemory on Mac, working on Windows

开发者 https://www.devze.com 2023-03-21 22:52 出处:网络
I have an application that loads data from a .csv file and shows it in a table. The application works correctly for all files (no matter what size it has) in windows, but it only works with the files

I have an application that loads data from a .csv file and shows it in a table. The application works correctly for all files (no matter what size it has) in windows, but it only works with the files that are lower than 8MB on Mac, any other file bigger than that throws me a "java.lang.OutOfMemoryError: Java heap space". I debugged the application to make sure that it was reading the .csv file and it does, but after a while it jush crashes with that error.

I did some research and try using the -Xmx and -Xms to increase the Java heap size but still get the same error.

The following code is where the application crashes after adding some of the arrays with information to the mainHashtable:

 while(reader.readRecord()){

        ArrayList<CSVEntry> list = new ArrayList<CSVEntry>();
        for(int i = 0; i < colscount; i++){
 开发者_开发技巧           CSVEntry entry = new CSVEntry(headerNames[i], reader.get(i));
            list.add(entry);
        }
        mainHashtable.put(recordcount, list);
        recordcount++;
}

Any suggestions that help me solve this issue will be gladly appreciated.


-Xmx is the correct answer. Java has odd defaults for maximum heap space depending on the platform (sometimes as low as 8MB).

If your application in bundled in a JAR with a Main-Class INF directive, the following should work for you:

java -Xmx256m -jar myapp.jar


Use the Java Bundler to generate an app
In the Properties tab, in the VM Options, insert: "-Xmx512m" without the quotes

0

精彩评论

暂无评论...
验证码 换一张
取 消