我在Eclipse下写一个java程序,遇到java.lang.OutOfMemoryError: Java heap space
问题。然后我运行
System.out.println(Runtime.getRuntime().freeMemory());
System.out.println(Runtime.getRuntime().totalMemory());
得到结果
1836656
2031616
就是说,JVM中内存总量才2M
于是我在Eclipse的window--preference--Java--Installed JRE下对安装的JRE edit。
发现Default Argunents一栏是空的,于是我添入
-Xmn100M -Xms300M -Xmx300M
按‘确定’后,再运行
System.out.println(Runtime.getRuntime().freeMemory());
System.out.println(Runtime.getRuntime().totalMemory());
结果显示内存已有300M
但是程序还是要内存溢出
请问:这样设置JVM的内存对吗,或怎么设置?
问题。然后我运行
System.out.println(Runtime.getRuntime().freeMemory());
System.out.println(Runtime.getRuntime().totalMemory());
得到结果
1836656
2031616
就是说,JVM中内存总量才2M
于是我在Eclipse的window--preference--Java--Installed JRE下对安装的JRE edit。
发现Default Argunents一栏是空的,于是我添入
-Xmn100M -Xms300M -Xmx300M
按‘确定’后,再运行
System.out.println(Runtime.getRuntime().freeMemory());
System.out.println(Runtime.getRuntime().totalMemory());
结果显示内存已有300M
但是程序还是要内存溢出
请问:这样设置JVM的内存对吗,或怎么设置?
更新到1.5试试。
我们公司以前也老出这个问题,服务器端更新为JDK1.5以后就没问题了
只是我的内存设置为2M时,从程序启动到内存溢出的时间和内存为300M时的时间感觉差不多
所以我想确认设置JVM内存的方法对否
System.out.println(Runtime.getRuntime().freeMemory());
System.out.println(Runtime.getRuntime().totalMemory());
不停的打印,看看内存的变化情况嘛....