讨论:什么情况下可能出现java.lang.OutOfMemoryError

westwin 2004-09-08 12:46:35
rt,请有经验的朋友说说看!
...全文
380 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
takecare 2004-09-10
  • 打赏
  • 举报
回复

Setting the New generation heap size
-XX:NewSize
Use this option to set the New generation Java heap size. Set this value to a multiple of 1024 that is greater than 1MB. As a general rule, set -XX:NewSize to be one-fourth the size of the maximum heap size. Increase the value of this option for larger numbers of short-lived objects.

Be sure to increase the New generation as you increase the number of processors. Memory allocation can be parallel, but garbage collection is not parallel.

Setting the maximum New generation heap size
-XX:MaxNewSize
Use this option to set the maximum New generation Java heap size. Set this value to a multiple of 1024 that is greater than 1MB.

Setting New heap size ratios
-XX:SurvivorRatio
The New generation area is divided into three sub-areas: Eden, and two survivor spaces that are equal in size.

Use the -XX:SurvivorRatio=X option to configure the ratio of the Eden/survivor space size. Try setting this value to 8, and then monitor your garbage collection.

Setting minimum heap size
-Xms
Use this option to set the minimum size of the memory allocation pool. Set this value to a multiple of 1024 that is greater than 1MB. As a general rule, set minimum heap size (-Xms) equal to the maximum heap size (-Xmx) to minimize garbage collections.

Setting maximum heap size
-Xmx
Use this option to set the maximum Java heap size. Set this value to a multiple of 1024 that is greater than 1MB.

takecare 2004-09-10
  • 打赏
  • 举报
回复
哈哈,你的“服务器”未免也太那个了吧?我的开发用机还P4 2.8E 1G 内存呢。
westwin 2004-09-10
  • 打赏
  • 举报
回复
另外,听说java里只有当使用native的方法时才会产生"内存泄漏".

所以我就想,如果不停的使用native方法,会不会对内存产生什么影响?
Crazysword 2004-09-09
  • 打赏
  • 举报
回复
takecare能具体讲一下都是指什么吗?谢谢!
我服务器内存只有512M
wandou999 2004-09-09
  • 打赏
  • 举报
回复
内存不够用
takecare 2004-09-09
  • 打赏
  • 举报
回复
To Crazysword:

试试这个,一下参数是我在很多项目中用到的。
-XX:MaxPermSize=64m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:SurvivorRatio=8 -Xms512m -Xmx512m
Crazysword 2004-09-09
  • 打赏
  • 举报
回复
怎么样测试内存使用情况呢?
flyingbug 2004-09-09
  • 打赏
  • 举报
回复
jvm使用的内存大小
或者程序错误,有些对象无法回收,又反复创建
所谓无法回收是指一直有指向它的引用存在
所以GC不回收它


你可以换个GC框架试试,用其他回收算法的
超时强制回收的那种,不知道jvm可不可以通过参数指定
Crazysword 2004-09-09
  • 打赏
  • 举报
回复
Tomcat5.0.16服务器在联系工作4到5天类就会出现这个问题java.lang.OutOfMemoryError。我在catalina.bat加了JAVA_OPTS='-Xms256m -Xmx256m'可是还是不行。请高手帮帮忙。
westwin 2004-09-09
  • 打赏
  • 举报
回复
呵呵,运行java时那个讨厌的dos窗口,如果这个讨厌的窗口的内存较小的话,应该也会OutofMemory吧,可以设置它的缓冲区大小.
kingfish 2004-09-08
  • 打赏
  • 举报
回复
内存不足时,如:
new byte[BUFFER_LENGTH];
westwin 2004-09-08
  • 打赏
  • 举报
回复
共享内存的使用不慎也可能导致OutofMemory
hpy121 2004-09-08
  • 打赏
  • 举报
回复
这一般都跟IO有关!
比如读入或产生一个非常大的文件流.
如果是进入死循环,一般不会有任何提示,而是象死机一样!
yema55 2004-09-08
  • 打赏
  • 举报
回复
无限递归或太多次的递归
westwin 2004-09-08
  • 打赏
  • 举报
回复
TinyJimmy(Jimmy):如使用不可垃圾回收的对象时没有close

敢问你说的不可垃圾回收的对象 是指哪些?
westwin 2004-09-08
  • 打赏
  • 举报
回复
我想楼上所说是有一定道理的,听说JProbe可以帮助找到程序的瓶颈所在.btw,调配jvm的参数固然可行,但是我觉得最主要的还是得想办法优化程序.
TinyJimmy 2004-09-08
  • 打赏
  • 举报
回复
主要是不当的设计或设计模式引起的。
如读一个100M的XML文件采用DOM
如将200000条记录生成对象装入内存
如使用不可垃圾回收的对象时没有close
。。。
nochess 2004-09-08
  • 打赏
  • 举报
回复
Dead loop will eat all the CPU timer, no memory.

It is very clear. Out of memory. e.g. open a large file and read all content.
takecare 2004-09-08
  • 打赏
  • 举报
回复
有很多内存不足问题可以通过调配JVM参数来解决的。
比如:
-XX:MaxPermSize=64m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:SurvivorRatio=8 -Xms512m -Xmx512m
westwin 2004-09-08
  • 打赏
  • 举报
回复
cuizm(射天狼) ,u r funny
加载更多回复(3)

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧