我在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的内存对吗,或怎么设置?
解决方案 »
- 我是菜鸟,请大神帮我看看这个代码哪里错了
- 就我这个没回复的,没人懂吗? Java JMF RTP 问题
- Swing和中文输入法的问题
- 付费求助,一个文件名比较复制
- 请教一个线程的问题
- 初学者的安装问题
- 怎样精确设置GridLayout布局中每个小格之间的间隙???
- 高手看过来!!!!+30分 这个Bean写的对吗?用来连接数据库的。
- Java连接数据库问题
- 线程之间通信的方式有哪些
- 一个MainFrame,左边是JTree, 右边是JTable。TreeSelectionListener单独成类,JTree和JTable的实现不在MainFrame中,要实现根据JTree的
- 怎样比较两日期?向高手请教。
更新到1.5试试。
我们公司以前也老出这个问题,服务器端更新为JDK1.5以后就没问题了
只是我的内存设置为2M时,从程序启动到内存溢出的时间和内存为300M时的时间感觉差不多
所以我想确认设置JVM内存的方法对否
System.out.println(Runtime.getRuntime().freeMemory());
System.out.println(Runtime.getRuntime().totalMemory());
不停的打印,看看内存的变化情况嘛....