aspose file tools*
The moose likes Performance and the fly likes Idle Java Application - Memory Leak? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Idle Java Application - Memory Leak?" Watch "Idle Java Application - Memory Leak?" New topic
Author

Idle Java Application - Memory Leak?

Jackson Tan
Greenhorn

Joined: Jun 01, 2010
Posts: 8
Hi, can someone help me. I have a j2ee web application. I want to monitor if it has a memory leak. I have a tomcat server that has only 1 deployed application I want to monitor. I ran the tomcat server last night and then run jconsole to monitor the memory usage of the application. After running the server, I didn't access the application. I left the server and the jconsole overnight in idle mode. This morning I saw that the memory usage of my application increases through time even if it is idle (no one accessing) See image below for the memory chart. I also force Garbage Collection in JConsole on the last part that's why memory went down on the last part of the chart. My question is does the memory chart say I have a memory leak in my application? But if I have a memory leak, why is it that after I perform GC the memory went down to normal. Any explanation or help will be appreciated. THanks

Jackson Tan
Greenhorn

Joined: Jun 01, 2010
Posts: 8
I attached another image below showing same application but I used/accessed the application during some time. In the chart below, I can see that from 1150-1250 I have again increasing memory usage. During this time, I didn't access the application but at 1251 onwards I access the application and the memory went back to normal again. Why is it that only during idle time of my application does the memory increase? Is it a problem in my application or the garbage collector? Thanks.

William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12678
    
    5
If your application is truly "idle" there should be no Thread executing and thus no object creation so this is pretty mysterious.

Is this server exposed to the Internet? Maybe it is getting hit by search robots....

Bill

Java Resources at www.wbrogden.com
Jackson Tan
Greenhorn

Joined: Jun 01, 2010
Posts: 8
I tested it only on my local, not on server. and yes it's connected to the internet. I will try to test again without internet connection. but is it possible that my application has a memory leak and that is the cause of this increasing memory usage even if in idle? Thanks
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2969
    
    9
It's possible you have a memory leak, sure. I don't know how or why, but yes, it's possible. However: have you seen it actually throw an OutOfMemoryError? Because right now it's nowhere near the maximum allowed memory (shown by the yellow line), so it may simply be that GC isn't trying very hard. It may be that if and when the graph gets closer to the yellow line, a more aggressive GC will be triggered. And that more aggressive GC ma be able to free more memory than the regular GC has. The behavior when you're well below max doesn't tell you that much, since the GC knows it doesn't really have to try very hard, yet.

I recommend waiting longer to see what happens over a longer time frame. Or, you can also run a test with -Xmx set to a much lower number, say 100000000 or 200000000 rather than the 500000000 shown. That will give you a much better idea whether there's a real problem here, or not.
Jackson Tan
Greenhorn

Joined: Jun 01, 2010
Posts: 8
Hi again, I have tested my application and again monitored its mem usage. Now, I accessed and processed transaction with my application. I processed about 20+ transactions and ran my application for about 5 hours. I think the app has a memory leak somewhere but I can't locate it. I used the YourKit Java Profiler tool to profile my app but I'm new to this and can't seem to find the leak. I don't know if traced the code correctly but I traced it to JAXBUtil and I don't know what to do especially that I didn't right the code for the JAXBUtil. I provided screenshots for the JAXBUtil, I hope someone can help me.. Thanks.

PS. I already Forced GC before getting the screenshots







Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

Your first graph does look like a slow leak, but it's nowhere near a risk to crash the server in the short term. I worked someplace where they just let stuff like that slide and rebooted the server once a week, although I don't consider that an ideal solution.

It might be beneficial to run an object analysis and see what the largest number of object classes are. #1 is usually java.lang.String, but #2 may be a user class. Full of java.lang.String members.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jackson Tan
Greenhorn

Joined: Jun 01, 2010
Posts: 8
I have already thought of that solution to reboot the server once a week but I want to find the leak somewhere. I want to learn how to find leaks and I used YourKit Java Profiler for the object analysis. I attached a screenshot of the list of objects that retain sizes. The thing is there's so many objects I don't know how to debug.. I already watched videos and searched for tutorial about the profiling but the examples in tutorials are too simple and obvious because they have large size memory leaks. I think I only have small leak so I'm having a hard time finding it. Can someone help or direct me for a tutorial in finding memory leaks? Especially using YourKit Java Profiler bec I already installed it. Anyways thanks for the reply Tim.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 15641
    
  15

It can be difficult. I spent most of a month tracking one. It turned out the be a "cache" that was actually an open-ended storage. Meaning that it didn't purge older objects, just got bigger and bigger and bigger until BLAM!

However, because it was a cache, the most objects were items IN the cache, so it took quite a bit of looking before I was able to realize that they were dependents on the objects that were actually leaking.
Jackson Tan
Greenhorn

Joined: Jun 01, 2010
Posts: 8
Can you give me examples or some tips on finding memory leaks? How did you find the memory leaks that are dependent on the objects in your cache?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Idle Java Application - Memory Leak?
 
Similar Threads
jconsole
Memory Leak?
java.lang.OutOfMemoryError: Java heap space
Is this a memory leak condition ?
How to troubleshoot a memory leak or an out-of-memory exception in the Weblogic Server