Tomcat memory leak

The following web applications were stopped (reloaded, undeployed),
 but their classes from previous runs are still loaded in memory, thus causing a memory leak (use a profiler to confirm): 

使用Maven 在Tomcat 上 重新部署项目时内存泄漏,原因之前的classes没有卸载还存在 jvm 内存中,
不过在有博主说在卸载项目之前先 stop一下项目,再 undeploy 就不会出现 memory leak

Stack Overflow:

If you want to make sure not to cause leaks you have to do the following:

  1. Make sure your web application does not use any java classes that are in the web container shared libraries. If you have any shared libraries, make sure there is no strong references to the objects in those libraries
  2. Avoid using static variables, especially on java objects like HashTable, Sets, etc. If you need to, make sure that you call remove to release the objects with the maps, lists…
    Here is also a good article on ThreadLocal and MemoryLeaks - http://blog.arendsen.net/index.php/2005/02/22/threadlocals-and-memory-leaks-revisited/

1是避免使用容器中的库,如果非要使用,避免使用强引用指向那些库
2是避免使用静态变量,特别是把map,set等容器作为静态变量

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

带着天使反上帝 - Kaybee

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值