Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Out of Memory

 
Geetha Gubendran
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Raj,

if there's enough physical memory in your machine you can simply start Java with additional parameters to increase the memory available to the JVM.


Java -X will give you an overview for more parameters.

Marco
 
Campbell Ritchie
Sheriff
Posts: 48921
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . 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.
 
arulk pillai
Author
Ranch Hand
Posts: 3387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic