开发者

How can I investigate a memory leak better in NetBeans

开发者 https://www.devze.com 2023-01-27 01:13 出处:网络
I\'m writing a web spider. It works well except there seems to be a memory leak. The program will run fine for about 15 minutes and then it will crash.

I'm writing a web spider. It works well except there seems to be a memory leak. The program will run fine for about 15 minutes and then it will crash.

If I monitor it using the "Profile" function in NetBeans, I can see that the memory is increasing over time until eventually I get a java.lang.OutOfMemoryError and the program crashes completely.

The image below shows snapshots of the memory of objects used aft开发者_如何学运维er one minute and after 15 minutes (right before it crashes.) Is there any way to tell where these objects (my main culprits are byte[] and char[]) are being created or what is still referencing them (and therefor preventing them from being destroyed by the garbage collector)?

Or do I have no idea what I'm talking about?

How can I investigate a memory leak better in NetBeans

Thanks, I appreciate the help.


You're probably right on track with your assumption, but maybe not using the right tool?

I don't know NetBeans, but I know both Yourkit Profiler and JProfiler to be very powerful tools for these kinds of analyses. You can walk the heap and analyse "hot spots". Both tools have a trial license, so you can try them out to see which one suits you best.


When you use the profiler to analyze the memory you can turn on recording of the stack traces for object allocation.

When you run in that mode, you can right click on the class and display the stack trace(s) where the objects are created. That should give you enough information to track down the memory leak.

You might want to read this article as well: http://netbeans.org/community/magazine/html/04/profiler.html

0

精彩评论

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