Personally feel that, because of the GC, most of the cases will not appear. However, if some resources are not shut down (for example, I/O files and database connections are not closed), it is possible that out of memory occurs.
Above, just personal experience to make the conclusion.
Here's an excerpt from: http://calvin.javaeye.com/blog/91903, a summary of Java memory leaks
Memory leaks
Isn't there a garbage collector in Java? How it still leaks.
Well, this leak is not more than leaking. C + + leakage, is the object is not reachable, and memory is not recycled, the real memory black hole.
The Java leak, for a variety of reasons, objects to the application has been useless, but has been held, can always be reached.
There are several reasons why:
1 is improperly held by a very long lifecycle collection class, claiming to be the first cause of Java memory leaks.
The life cycle of these collection classes is usually extremely long and is an object of a secondary management nature, after a business transaction has run out, if a business object master
This collection will eat more and more memory when the move is removed from it.
2 scope definition is not correct, this is very simple, the method of local variables defined as class variables, class static variables.
3 exception without finally{} to release some resources, the JDBC era is also a common thing.
4 other reasons I do not understand deeply, such as: swing in the listener without explicit remove; internal classes hold implicit references to external objects; Finalizers cause off
The object was not emptied in time.
Detection of memory leaks
There are a lot of tools to help with this, and if you don't have a tool on your hand, you can use the JDK with your own gadget:
Look who's filled up with heap.
1 with JDK6 Jmap can display the types of objects in the running program, the number and size of the
2 First Use JPS to find the process number, and then Jmap-histo PID display or jmap-dump:file=heap_file_name PID export heap File
Why these objects can still be reached.
3 Analyze the Heap file just exported using Jhat (Java Heap analysis Tool).
4 Jhat heap_file_name First, then open browser http://localhost:7000/Browse.