我在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的内存对吗,或怎么设置?

解决方案 »

  1.   

    JDK是多少?
    更新到1.5试试。
    我们公司以前也老出这个问题,服务器端更新为JDK1.5以后就没问题了
      

  2.   

    设置jvm的内存是设对了,应该就是你代码的问题了,300M还会溢出,检查一下是哪儿吃内存的
      

  3.   

    我是在用fp树挖掘频繁项集,吃内存是对的,尤其是支持度小的时候
    只是我的内存设置为2M时,从程序启动到内存溢出的时间和内存为300M时的时间感觉差不多
    所以我想确认设置JVM内存的方法对否
      

  4.   

    你在循环的地方用一下
    System.out.println(Runtime.getRuntime().freeMemory());
    System.out.println(Runtime.getRuntime().totalMemory());
    不停的打印,看看内存的变化情况嘛....