Sunday, November 8, 2009

Java - Out of Memory Exception


The out of memory issue shall be because of the following reasons.

  •          It can happen, particularly if your application involves a large amount of data processing, or is long lived – such as a server that responds to requests and is expected to run indefinitely
  •          The virtual machine  Java program is running on may have a limit to the amount of memory it will give access to, the system on which  program is running may have run out of physical and virtual memory
  •          Too many threads running
  •      An abnormal execution condition was synchronously detected by a Java Virtual Machine
Solutions for OutofMemoryException:-
1.Application redesign will give more effect.
2.Code codewise any memory leak is there i mean any of the collection classes creating 
number of times,reading huge records from database,unused objects cleanup.
3.Try to avoid collection classes like Vector,HashSet….

http://www.javacommerce.com/displaypage.jsp?name=java_performance.sql&id=18264 



Following also useful in some conditions. 
Code cleanup  using IntelliJIDEA tool.


1. Field Variable converted to local variables.

2. Removed Manual Array to collection copy (inside for loop)

3. Reduntant String.toString()

4. Reduntant string Constructor call

5. Replaced StringBuffer with StringBuilder

6.
equals (“”)
replaced with length()==0

7. Removed Filling Array inside the loop

8. Remove unused variables and Imports

9. Remove Unneccessary toString() conversion

10.Remove creating String object while adding into a ArrayList

0 Comments:

Post a Comment

The Link Exchange - Your ultimate resource for link exchange!

About This Blog

  © Blogger template Webnolia by Ourblogtemplates.com 2009

Back to TOP