top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to detect memory leak in java?

–1 vote
760 views
How to detect memory leak in java?
posted Sep 8, 2013 by Vinay Shukla

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button
What have u tried, its important to know what you have tried before someone suggest you what is the homework u have done.

3 Answers

+1 vote

you may want to check out jconsole. It's also part of the JDK and I have found it helpful to find emory/reference leaks in conjunction with jhat. Also take a look at this blog http://blog.emptyway.com/2007/04/02/finding-memory-leaks-in-java-apps/

answer Sep 9, 2013 by Luv Kumar
+1 vote

I suggest you use visualvm that comes with JDK 5 onwards.

If your code creates an object and has more than 3 level of reference of it or if Java garbage collector algorithm thinks that this object may be referenced by any your code than it is not garbage collected.
therefore it becomes memory leak.

Where do these occurs in java code?
Most vulnerable code in Static class, singleton class or static methods where you want instance object to be alive in multiple condition/scenario for unknown time in objects life cycle, may result into object left over (read stay in memory without any further use) and GC unable to decide if it can be GC'ed. Therefore memory leak.

answer May 4, 2015 by Priya Ranjan Kumar
0 votes

There is no sure sort answer but you can use profile and memory dump to find memory leak in Java. JConsole can also help to provide graph of memory usage which can show pattern for memory leak.

answer Sep 9, 2013 by Arvind Singh
Similar Questions
+5 votes

My doubt is that doesn't Java virtual machine have a garbage collector that will collect and free all unreferenced memory automatically?

+2 votes

I am looking for a free/open source tool to identify memory leaks in my JNI program.
I am using : java version "1.6.0_45", Java HotSpot(TM) 64-Bit Server.

Any suggestions?

0 votes

I've written a program using Twisted that uses SqlAlchemy to access a database using threads.deferToThread(...) and SqlAlchemy's scoped_session(...). This program runs for a long time, but leaks memory slowly to the point of needing to be restarted. I don't know that the SqlAlchemy/threads thing is the problem, but thought I'd make you aware of it.

Anyway, my real question is how to go about debugging memory leak problems in Python, particularly for a long running server process written with Twisted. I'm not sure how to use heapy or guppy, and objgraph doesn't tell me enough to locate the problem. If anyone as any suggestions or pointers it would be very much appreciated!

...