Please give me pointers on handling this issue in a right way. How could i find the memory problem and solve it? What tool can be used? What tweaks i can do to find the problem. Any pointers would be helpful.
You run out of memory if you just create too many objects and save the references, if the object you are creating is too large to handle, some I/O is being done which consumes too much of resources and may other cases.
XMX and XMS parameters to the JVM set how much memory to give to JVM. But, simply giving yourself more won't fix the problem, if you keep creating too many objects - you can still run out of memory eventually.
Well, I don't think there is a specific tool for finding such issue. You just have to check if your code is well as per performance constraints.
A few guidelines can be :
- Checking if all I/Os are opened & closed properly
- DB connections and sessions are handled effectively
- Some loop which undesiredly is creating larger number of objects
- Too many refrences without bothering to clean them.
Simple
word is to optimize. In this process you basically need to find which code segment makes that problem often and then hit that part.