If Java application has a memory leak, the JVM would eventually run out of memory and flag, right?
I think the answer to this question should be yes...but I guess I'm not really sure,开发者_如何学JAVA since I'm asking about it:)
I'm just trying to determine if my webapp has a memory leak somewhere. If the memory usage continues to increase, an Out of Memory error should be produced eventually, right?
Yes.
If you have a substantial leak you eventually get an OutOfMemoryError.
Although, if you have a small leak, it's possible to run for a long time without running out of memory. It depends on the size of the leak, heap size, and how long your servers run before an update or restart.
Yes if the memory usage continues to increase.
However, a memory leak is a situation where memory has been allocated and not released when it is no longer relevant. The definition does not mean that it has to be recurring or growing.
For instance, if you had 4GB of RAM in your JVM, had a bunch of leak events that ate up 3GB and are not going to have any more memory leak events, you are still restricted to the limited 1GB.
Therefore, you could very well have a leak, even a serious one, but not spot it until you've had enough events that would cause you to run out of memory or until the performance of other parts degenerates too much.
In my experience, these situations are more common that one would expect, making them notorious to track down.
Eventually. The JVM has a notion of maximum heap size, meaning if it reaches the limit and tries to allocate more and can't, it will try to garbage collect; if it still can't allocate memory, you will get an exception thrown.
If you are trying to find a memory leak, monitoring your webapp using jconsole might be a good idea. Also JProbe can be used to identify leaks.
There are many tools available for analyzing, and many times automatically isolating, possible memory leaks. jhat ships with the JDK; Eclipse Memory Analyzer is free, and an example commercial offering is YourKit.
精彩评论