I have a doubt. If there is a project which is developed using a pure core java. If that project is running in production but throws out of memory error. How will that error be fixed? Can somebody help me with this?
. . . and make sure you don't have some sort of collection gradually collecting object references which ought to have beet assigned to null, or anything like that.
In Java, typically memory leak occurs when an object of a longer lifecycle has a reference to objects of a short life cycle. This prevents the objects with short life cycle being garbage collected. The developer must remember to remove the references to the short-lived objects from the long-lived objects. Objects with the same life cycle do not cause any issues because the garbage collector is smart enough to deal with the circular references
-- Use tools like JProbe, OptimizeIt etc to detect memory leaks.
-- Use operating system process monitors like task manager on NT systems, ps, vmstat, iostat, netstat etc on UNIX systems.
-- Write your own utility class with the help of totalMemory() and freeMemory() methods in the Java Runtime class. Place these calls in your code strategically for pre and post memory recording where you suspect to be causing memory leaks. An even better approach than a utility class is using dynamic proxies (Refer Q11 in How would you go about section�) or Aspect Oriented Programming (AOP) for pre and post memory recording where you have the control of activating memory measurement only when needed. [ June 02, 2008: Message edited by: arulk pillai ]