在java项目中的内存问题

在我现在进行的java项目中,我采用的是基于struts的b/s项目,其实项目也不大,使用的是tomcat作为服务器,现在在运行的过程中,发现tomcat耗用的内存在不断的增加,到了一定的时候,就会报out of memery的错误,由于我不知道项目的哪些部分程序耗用内存,我现在采用java -Xms10M -Xmx1G的形式来解决,不过我觉得这样不是很好。不知到有什么工具或者方法能够检查出哪些程序耗用内存,没有进行释放。
谢谢各位

因为 String 而出现 OutofMemory 错误的机率比较大,所以请先检查一下看看有没有什么地方有 String.toArray() 之类的方法调用?
大文本的处理要比较小心,即使把内存加到 1G,如果使用不当,OutofMemory 还是会出现。

borland的optimizeit就是可以来检查java内存的问题,不过我没用过,不知道好不好用。

不过好像有文章讲过java中主要的内容问题是在String上。

如果String对象会有 “+=”之类的操作,还是用StringBuffer类吧。
其他我也不是很清楚,原来听别人说用了struts效率比较低,也不知道问题在哪?

When you suspect there is a memory leak, start with small memo footprint, watch GC behavior, this will give you an idea whether memo increasement is caused by transient( possibly big chuncks, or two frequent allocation requests) or non-transient( a true memory leak). If you had identified a memory leak, then use profiling tools.

Increase Xmax will only alleviate your problem in dev time, but can cause fatal disaster in prodution. So don't do it. On the contrary, in debugging, you would reduce the Xmax to accelarate the syndrome for small apps.

Cheers,
-Jevang

其实我也知道用-Xmxn 是不合适的,不过你说使用profiling tool,我也简单的用了一下-Xrunhprof来看,感觉不太好用。不知这位大侠能否推荐一下有关的好用的工具(最好是免费的)。
谢谢了

问个菜鸟问题 如何在tomcat 里设置 -Xms10M -Xmx1G 这几个参数.

很明显,你的系统存在内存泄漏(不是tomcat), 查找内存泄漏可使用Borland的Optimizeit等工具。

从性能的角度来说

使用 struts绝对比单纯用servlevt/jsp消耗资源


原因:从对象的继承链来说

一个formbean和action的继承链好几层

每一次的new对象。比较消耗资源