Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures


Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips


Submit News
Search the site here...
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

I am getting ''OutOfMemoryError''. How do I prevent such memory leaks?

JavaFAQ Home » General Java Go to all tips in General Java

Bookmark and Share

Question: I am getting "OutOfMemoryError". How do I prevent such memory leaks?

Answer: It is not always a memory leak that causes "OutOfMemoryError".
A memory leak is a situation when some application, for example JVM allocates some amount of memory and then loses pointers to that area. So, the allocated area becomes a "black box" which you can not access and you need a key to open it.
It is very rare situation when some Java code causes memory leaks.
They are reported and can be found at "Bug parade" on SUN's web site.

"OutOfMemoryError" often caused by bad design. It can be for example:

1. Your program trying to process too much data. Increase the amount of memory or decrease the amount of data to be processed.
Actually you can do it in a wise way: control how much memory left and if it less than, let say 20 %, decrease the processing speed.
It was described in one of our tips while ago...

2. Your program holding too many objects and then program is running out of memory.
You need to use close methods if you do need them. You can even explicitly set a reference to null to speed up garbage collection.

3. You use too many objects with finalizers... They consume your memory before you get any chance to run them...

 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search

Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy