Loading
OutofmemoryError

Java Quick Notes

Refresh Your Java - Before Java Interview

We are Agile, believe in less Documentation - Only Quick notes (Java Interview Questions) of Java/J2ee Read more....


Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet
Not Included Yet

Go to SiteMap

Q)  How to solve "OutofmemoryError" ?


  • OutofmemoryError ?
    Sample Img 5

Ans)

"OutofmemoryError" error occurs when JVM is unable to allocate Memory for creating any
new variables while performing some task.

This could be solved in by following steps:

i) First and foremost, check the memory settings of your application (JVM), if there is
any scope to increase the Memory settings, please change those, if not you may need to
tune the application. So first please review the Memory Parameters i.e. "-Xmx. -Xmx" values,
usually you could find these in SetEnv bat (or .sh) file or you could also  provide these as
System (-D) parameters to JVM.

-Xmn512M -Xms1024M

ii) Tune the application by using some Profilers such as JProfilier or Optimize it and make sure
all Unused objects are reachable to Garbage Collectors by setting the NULL value to
garbage-collect them.

iii) Use soft Or Weak references to avoid this as shown below.
     private  SoftReference<byte[]> bufferRef;

iv) Close all Database Connections and File IO streams properly in Finally block as
shown below and avoid connection leaks.
     try{
        } finally {
          con.close();
     }
v) Close all IO streams which are used for performing File operations such as filinputsteam
 or filinputsteam.
          FileInputStream fin = null;
     try{ 
         fin = new FileInputStream(file)
        } finally {
          fin.close();
     }
vi) See if you could use Object Pool instead of creating unlimited new Objects.

 



Back to top

------------------------- We hope you got necessary Info On -----------------------------------------

OutofmemoryError


OutofmemoryError

-------------------------------------------------------------------------------------------------------



Face Book
Request for a Mock Interview/Training

Get a PDF

Face Book
Same look (Read) on any device, this is Ads free