java.lang.OutOfMemoryError: Java heap space importing a serialized file in eclipse

java.lang.OutOfMemoryError: Java heap space importing a serialized file in eclipse

当我尝试在主程序中导入序列化文件时,程序停止工作并抛出:Exception in thread "main" java.lang.OutOfMemoryError: Java heap space。 我知道由于内存不足可能会引发此异常,但我认为这不是这种情况的原因。 在我的电脑中,我有 8gb 的 RAM。这是 Eclipse 的 .ini 文件:

-startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20140415-2008.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20150204-1316
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
1024M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
1024m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.6
-Xms512m
-Xmx7500m
-XX:+UseConcMarkSweepGC
-XX:-UseGCOverheadLimit

我注意到虽然eclipse几乎可以使用我电脑的所有内存,但是当这个错误发生时,使用的RAM大约只有5Gb。 我要导入的文件是 500Mb。同一程序适用于许多 350Mb 的文件。 这是程序粉碎的代码行,也是我程序的第一行:

Classifier cls1 = (Classifier) weka.core.SerializationHelper.read("C:\Users\.....\FileToImport.model");

谁知道呢,我正在使用 Weka 库。 谢谢你的回答!

'eclipse.ini' 文件为 Eclipse 本身设置内存而不是您的程序。

要为您的程序设置内存,请打开 'Run > Run Configurations' 对话框。在 Java 应用程序部分找到您的程序,并在 'Arguments > VM arguments' 部分指定您想要的 -Xmx 选项。