Mac 上的 Java OutOfMemory,可在 Windows 上运行
我有一个从 .csv 文件加载数据并将其显示在表格中的应用程序。该应用程序适用于 Windows 中的所有文件(无论大小),但它仅适用于 Mac 上小于 8MB 的文件,任何其他大于该文件的文件都会抛出“java.lang.OutOfMemoryError: Java”堆空间”。我调试了应用程序以确保它正在读取 .csv 文件并且确实如此,但过了一会儿它就会因该错误而崩溃。
我做了一些研究并尝试使用 -Xmx 和 -Xms 来增加 Java 堆大小,但仍然遇到相同的错误。
以下代码是在将一些带有信息的数组添加到 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++;
}
任何帮助我解决此问题的建议将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
-Xmx
是正确答案。 Java 对最大堆空间有奇怪的默认值,具体取决于平台(有时低至 8MB)。如果您的应用程序捆绑在带有 Main-Class INF 指令的 JAR 中,则以下内容应该适合您:
java -Xmx256m -jar myapp.jar
-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
使用 Java Bundler 生成应用程序
在“属性”选项卡的“VM 选项”中,插入:“-Xmx512m”(不带引号)
Use the Java Bundler to generate an app
In the Properties tab, in the VM Options, insert: "-Xmx512m" without the quotes