简体   繁体   中英

How can I investigate a memory leak better in NetBeans

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 after 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?

替代文字

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM