If you see that Java Heap increases over time and does not go down during Full GC / OC calls , then you most likely have a Memory Leak.
Heap Dump analysis is needed to figure out what is going on in your situation. Here are some Possible Memory Leak Scenarios.
HTTP Session
If you are dealing with Out of memory in your Web Application, it might be related to HTTP Sessions.
- Too many HTTP Sessions in your JVM.
- Increase members in your Cluster to distribute users across more JVMs.
- If you are using JSF, you may want to modify web.xml for "org.apache.myfaces.trinidad.CLIENT_STATE_MAX_TOKENS". Default for this value is 15, it is possible to set this value to lower value for example 5.
- Large Objects in HTTP Session
- Analyze what you have in HTTP Session and optimize your application to avoid having larger objects in HTTP Session. (There is overhead of Serializing HTTP Session in Clustered environment, so it is best to keep HTTP Session to a smaller size)
Object Cache
If you have a Cache (Java Map , Oracle Coherence near cache etc) in your process, Check for all your Key objects and it's usage.
- If your Key object does not implement hashCode() and equals() methods properly, it would lead to memory leak in cache implementation.
- Alway implement hashCode() and equals() methods properly.
- If your Key object has proper implementation of hashCode() and equals() method, but you reuse Key object for multiple Put calls. For example, you create Key object then put some object in cache, then modify same Key object and use it to put a different ojbect in same or different Cache.
- Create immutable Key objects (no setter methods on Key object) if possible. Or if this is not possible, take extra care while coding Cache calls to use a new / clone key objects.