内存不足时,如:
new byte[BUFFER_LENGTH];

解决方案 »

  1.   

    我想一般都是使用不当引起的。
    比如在死循环或者线程不停的创建对象,导致回收不如创建快。
    还有就是JVM的系统参数调配的不合理。
      

  2.   

    cuizm(射天狼) ,u r funny
      

  3.   

    有很多内存不足问题可以通过调配JVM参数来解决的。
    比如:
    -XX:MaxPermSize=64m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:SurvivorRatio=8 -Xms512m -Xmx512m
      

  4.   

    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.
      

  5.   

    主要是不当的设计或设计模式引起的。
    如读一个100M的XML文件采用DOM
    如将200000条记录生成对象装入内存
    如使用不可垃圾回收的对象时没有close
      

  6.   

    我想楼上所说是有一定道理的,听说JProbe可以帮助找到程序的瓶颈所在.btw,调配jvm的参数固然可行,但是我觉得最主要的还是得想办法优化程序.
      

  7.   

    TinyJimmy(Jimmy):如使用不可垃圾回收的对象时没有close敢问你说的不可垃圾回收的对象 是指哪些?
      

  8.   

    共享内存的使用不慎也可能导致OutofMemory
      

  9.   

    呵呵,运行java时那个讨厌的dos窗口,如果这个讨厌的窗口的内存较小的话,应该也会OutofMemory吧,可以设置它的缓冲区大小.
      

  10.   

    Tomcat5.0.16服务器在联系工作4到5天类就会出现这个问题java.lang.OutOfMemoryError。我在catalina.bat加了JAVA_OPTS='-Xms256m -Xmx256m'可是还是不行。请高手帮帮忙。
      

  11.   

    jvm使用的内存大小
    或者程序错误,有些对象无法回收,又反复创建
    所谓无法回收是指一直有指向它的引用存在
    所以GC不回收它
    你可以换个GC框架试试,用其他回收算法的
    超时强制回收的那种,不知道jvm可不可以通过参数指定
      

  12.   

    To Crazysword:试试这个,一下参数是我在很多项目中用到的。
    -XX:MaxPermSize=64m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:SurvivorRatio=8 -Xms512m -Xmx512m
      

  13.   

    takecare能具体讲一下都是指什么吗?谢谢!
    我服务器内存只有512M
      

  14.   

    另外,听说java里只有当使用native的方法时才会产生"内存泄漏".所以我就想,如果不停的使用native方法,会不会对内存产生什么影响?
      

  15.   

    哈哈,你的“服务器”未免也太那个了吧?我的开发用机还P4 2.8E 1G 内存呢。
      

  16.   


    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.