开发者

what causes memory leak in java

I have a web application deployed in Oracle iPlanet web server 7. Website is used actively in Internet.

After deploying, heap size is growing and after 2 or 3 weeks, OutO开发者_StackOverflow中文版fMemory error is thrown.

So I began to use profiling tool. I am not familiar with heap dump. All I noticed that char[], hashmap and String objects occupy too much at heap. How can I notice what causes memory leak from heap dump? My assumptations about my memory leak;

  • I do so much logging in code using log4j for keeping in log.txt file. Is there a problem with it?

  • may be an error removing inactive sessions?

  • some static values like cities, gender type stored in static hashmap ?

  • I have a login mechanism but no logout mechanism. When site is opened again, new login needed. (silly but not implemented yet.) ?

  • All?

Do you have an idea about them or can you add another assumptions about memory leak?


Since Java has garbage collection a "memory leak" would usually be the result of you keeping references to some objects when they shouldn't be kept alive. You might be able to see just from the age of the objects which ones are potentially old and being kept around when they shouldn't.

  • log4j shouldn't cause any problems.
  • The hashmap should be okay, since you actually want to keep these values around.
  • Inactive sessions might be the problem if they're stored in memory and if something keeps references to them.


There is one more thing you can try: new project, Plumbr, which aims to find memory leaks in java applications. It is in beta stage, but should be stable enough to give it a try.

As a side node, Strings and char[] are almost always on top of the profilers' data. This rarely means any real problem.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜