What's the best way to resolve a GWT memory leak due to the fact that GWT is compiled in javascript and code is written in JAVA ?
I can recommend 2 things:
Read this article
Nullify all references when you done with them.
Good luck!
In GWT development mode you can use a Java profiler such as VisualVM or JProfiler (disclaimer: JProfiler is developed by my company) to analyze the heap.
The GWT development mode should show the same leak as well, except for the less likely case that the leak related to the Javascript translation (which would then be a bug in GWT).
Related
I've managed to get a memory 'leak' in a java application I'm developing. When running my JUnit test suite I randomly get out of memory exceptions (java.lang.OutOfMemoryError).
What tools can I use to examine the heap of my java application to see what's using up all my heap so that I can work out what's keeping references to objects which should be able to be garbage collected.
VisualVM is included in the most recent releases of Java. You can use this to create a heap dump, and look at the objects in it.
Alternatively, you can also create a heapdump commandine using jmap (in your jdk/bin dir):
jmap -dump:format=b,file=heap.bin <pid>
You can even use this to get a quick histogram of all objects
jmap -histo <pid>
I can recommend Eclipse Memory Analyzer (http://eclipse.org/mat) for advanced analysis of heap dumps. It lets you find out exactly why a certain object or set of objects is alive. Here's a blog entry showing you what Memory Analyzer can do: http://dev.eclipse.org/blogs/memoryanalyzer/2008/05/27/automated-heap-dump-analysis-finding-memory-leaks-with-one-click/
If you need something free, try VisualVM
From the project's description:
VisualVM is a visual tool integrating commandline JDK tools and lightweight profiling capabilities. Designed for both development and production time use.
This is a pretty old question. A lot of people might have started using IntelliJ since it was originally answered. IntelliJ has a plugin that can show memory usage called JVM Debugger Memory View.
Use the Eclipse Memory Analyzer
There's no other tool that I'm aware of any tool that comes close to it's functionality and performance and price (free and open source) when analysing heap dumps.
Use a profiler like JProfiler or YourKitProfiler
JProfiler worked very well for me....
http://www.ej-technologies.com/products/jprofiler/overview.html
If you're using a system which supports GTK you could try using JMP.
You can try the Memory Leak Detector that is part of the JRockit Mission Control tools suite. It allows you to inspect the heap while the JVM is running. You don't need to take snapshots all the time. You can just connect online to the JVM and then see how the heap changes between garbage collections. You can also inspect objects, follow references graphically and get stack traces from where your application is currently allocating objects. Here is a brief introduction.
The tool is free to use for development and you can download it here.
Hi I'm having a real big problem on this. Is there any tool or process that can identify memory leaks on my java webapps. Im currently using spring, hibernate, c3p0.
You can try tools like VisualVM/JProfiler/Yourkit. To analyze which of your objects are taking up memory.
VisualVM comes with JDK, however Others might need a purchase as well.
This link provides a clear explanation on how to detect memory leaks and resolve them.
I have project written in java that using JNI uses a C++ library.
All the code was written by us, so I have all the source code.
After few hours the machine runs out of memory although my process just iterate over files and all the memory regarding the previous file deleted.
I'm sure that there is a memory leak, usually I use Valgrind, but it seems he can't cope with Java very well and believes that the JVM is leaking, even for "hello world" java project.
I've tested the C++ parts (the major flows) with unit-tests and used valgrind on the unit-tests, but couldn't find any leakage. It doesn't prove anything because there are many potential flows I could've missed.
My major question, how can I find my leak ?
It will be extremely helpful to know who is consuming the memory, the java or the native part ? they are in the same process.
Thanks.
You can use jemalloc to debug native memory leaks. This blog post has a detailed example of using jemalloc to debug a native memory leak in java applications.
From my experience, Valgrind is actually usable with the JVM, and it remains the best tool to hunt leaks in C/C++ code, even with JNI. So your question kinda contains the answer that you need ;)
If you fail to use JNI and Valgrind together, please refer to Valgrind and Java.
I am suspecting a native memory leak in my java code. Are there any tools which do native memory profiling? Also, does any tool support native memory analysis of a running java process?
Thanks!!
Edit:
I have already tried Memory Validator and Purify but it seems they support only 32-bit processes. Is there some tool similar to the above ones which can simply attach to a running windows process and give us native memory analysis for that particular process?
The Troubleshooting guide for Java SE 6 with Hotspot VM contains a fairly elaborate section on techniques to aid in detecting native memory leaks. These include:
wrapping all memory allocation and deallocation calls to track the amount of memory used.
relying on platform specific support like the debug support provided by the Microsoft Visual C++ compiler or on mtrace (and MALLOC_TRACE) to debug memory allocations on Linux.
using memory leak analysis tools like Rational Purify.
among others. Notably, the article mentions that no ideal solution exists for all platforms.
Also, consider using the -Xcheck:jni flag that appears to be available in most JVMs. The -X flag itself indicates that the flag is non-standard, but the flag appears to be available in the IBM JDK, Oracle JRockit R28, and even the Oracle/Sun JVM. Enabling the flag switches on a mode where wrappers are added around JNI calls, thereby allowing you to track illegal arguments passed to JVM calls as noted in the JNI programmers' guide and specification. While, it's use in detecting memory leaks is subjective, it would definitely help if you suspect that the leak is being caused due to invalid parameters being issued.
AFAIK you can't do it with Java tools like JProfiler, JVisualVM etc. If you have memory leak in native code use tools for native code. You ie. can run it from C (i.e. loading jvm.dll). You can look at this articles finding memory leaks using Visual Studio or Memory Leak Detection in C++ (Linux)
Note: of course if you leak is connected to heap leak (forgot about deleteglobalref) you can find it with Java tools, but it is very rare in JNI.
I have been working on an open-source project named "MySafe" (https://github.com/serkan-ozal/mysafe) It basicly intercepts and monitors "Unsafe" calls. (In fact, it makes more than). With version 2.0, it can be useful for tracking and detecting "Unsafe" based native memory leaks.
Demo code: https://github.com/serkan-ozal/mysafe/blob/master/src/test/java/tr/com/serkanozal/mysafe/NativeMemoryLeakHuntingDemo.java
Diagram showing source of the leak: https://github.com/serkan-ozal/mysafe/blob/master/src/test/resources/native-memory-leak-hunting.png
To diagnose native memory leak, JIT code symbol mapping and Linux recent profiling tools are required: perf, perf-map-agent and bcc.
Please refer to details in related answer https://stackoverflow.com/a/52767721/737790
Many thanks to Brendan Gregg
These are tools you can use for debugging
libtcmalloc HPROF: For heap profiling
The jcmd Utility, PSS for the process: Can help in confirming a native leak.
Native Memory Tracking: Tracking native memory leak in JVM (only works for allocation inside JVM)
Core dump analysis, pmap and gdb checking for anon blocks and process memory overtime
-Xcheck:jni
Further details can be found out here
https://www.bro-code.in/blog/java-debugging-native-memory-leak
http://www.oracle.com/technetwork/java/javase/memleaks-137499.html#gbyvk
I'm a big fan of JProfiler. That's the best tool for profiling and memory leaks. It's fairly cheap relative to most tools, really easy to learn, and lots of features.
http://www.ej-technologies.com/products/jprofiler/overview.html
My multithreaded Java program crashes because it runs out of heap space and I don't think it should. Assuming the culprit is unintentional object retention, what's a good free tool to investigate what objects are being unintentionally retained?
My IDE is Eclipse.
Here's a list of open source tools you can look at: http://java-source.net/open-source/profilers . Of course, JMap and JConsole are also possible solutions.
A tool like Eclipse MAT will help to find greedy memory pigs and has even a memory leak detector.
The memory profiler of Visual VM might also help if you need to go at a lower level.
The last time I looked into free profilers, they weren't nearly as good as the established commercial ones.
I recommend evaluating
JProfiler
YourKit
JProbeand investing the money for a license of the tool you like best.
A good profiler, compared to a bad one, can easily save you a day of debugging work immediately and that pays for the license (and for the people doing the great job developing these nice tools).
All three plug into Eclipse and allow you to start profiling directly from Eclipse, from your current project, so there is no tedious work to set up the CLASSPATH.
Sun's VisualVM is free, but I am a big fan of JProfiler which is a commercial app, although you can get a 30 day trial.
I would start with tools that come with JDK, jconsole and jmap. There is good article about JVM monitoring on java.sun.com.