September 04, 2010, 04:01:34 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  Home Help Media Affiliates Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: java.lang.OutOfMemoryError  (Read 1967 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2620
Referrals: 13

WWW Awards
« on: August 09, 2007, 02:31:25 AM »

This error message can occour while running your application.

The error 'java.lang.OutOfMemoryError: Java heap space' is caused when the JVM (Java Virtual Machine) runs out of available memory during processing.  This can be caused by:
    * a system with less memory than your application / VM requires.

Sample program that causes this error:
Code
GeSHi (java):
  1. import java.util.Vector;
  2.  
  3. /*--------------------------------------------------------------------------
  4. //Author List:
  5. // deAppel <Creator>
  6. //
  7. //Description:
  8. // Showing java.lang.OutOfMemoryError
  9. //
  10. //Environment:
  11. // This software was developed using Eclipse and Java 1.6
  12. //
  13. //Copyright Information:
  14. // Copyright (C) 2007      <Institution><None>
  15. // Ark de Appel www.engineeringserver.com
  16. //
  17. //----------------------------------------------------------------------*/
  18.  
  19. public class OutOfMemory {
  20.  
  21. public static void main(String[] args) {
  22. boolean tmp = true;
  23. int i = 0;
  24. Vector v = new Vector();
  25. while (tmp == true) {
  26. v.add(i);
  27. i++;
  28. }
  29. }
  30. }
Created by GeSHI 1.0.7.20

When you run this you will get:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
   at java.util.Vector.ensureCapacityHelper(Unknown Source)
   at java.util.Vector.add(Unknown Source)
   at OutOfMemory.main(OutOfMemory.java:10)

Why?
Because tmp is always true,  the while loop never stops and it continues to add the variable i into the vector until the JVM runs out of memory.

Solution(s):
    * add more RAM
    * typ: java -Xmx256m in your console window or java -XmxYYYm where YYY is the amount of memory you want to set.

Reference:
http://bliki.rimuhosting..../linux/java/-Xmx+settings
http://edocs.bea.com/wls/...61/perform/JVMTuning.html
http://forum.java.sun.com...read.jspa?threadID=745025
« Last Edit: August 09, 2007, 02:38:06 AM by HappyFace » Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Javaforums.net :: a community about Java software development.
« on: August 09, 2007, 02:31:25 AM »

Your Ad Here
 Logged
gluk
Member
*

Reputation: 0
Offline Offline
Posts: 22
Referrals: 0

Awards
« Reply #1 on: April 21, 2009, 05:43:54 PM »

The solution for most of the Java related errors can be found at this site: Java errors and solutions.
« Last Edit: April 22, 2009, 12:47:49 PM by HappyFace » Logged
Javaforums.net :: a community about Java software development.
   

 Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.10 | SMF © 2006-2009, Simple Machines LLC
TinyPortal v0.9.8 © Bloc
Valid XHTML 1.0! Valid CSS!
Page created in 0.218 seconds with 33 queries.

Google visited last this page September 01, 2010, 04:51:27 PM