LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Java Heap Space (https://www.linuxquestions.org/questions/programming-9/java-heap-space-618339/)

manolakis 02-03-2008 05:45 AM

Java Heap Space
 
Hi there

Does anybody know how to overcome the following exception?

Quote:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at sun.misc.FloatingDecimal.dtoa(FloatingDecimal.java:661)
at sun.misc.FloatingDecimal.<init>(FloatingDecimal.java:442)
Thanks

Mega Man X 02-03-2008 07:38 AM

Most likely, your application has a memory leak. Try to increase the heap space like this:

java -Xms128m -Xmx512m

That will reserve a minimum of 128Mb for the heap, with a max of 512Mb. I am not sure what the default values are though... but I'd still check for memory leak first.

Alien_Hominid 02-03-2008 12:29 PM

If I remember correctly, default is 64Mb.

sundialsvcs 02-04-2008 11:15 PM

If you are experiencing heap-overflow problems in a language like Java, it's important to understand key principles of how such languages are designed to work: most importantly, garbage collection.

Unlike languages such as "C," you don't have to explicitly free anything. You can acquire a new object, use it, and forget about it. The garbage-collection routines will clean up after you, reclaiming the space you're no longer using.

The Java specification does not stipulate how the garbage collector will work, only that there must be one. The most common implementation for a garbage-collector uses reference counting. An object continues to exist until its reference-count becomes zero. Counter-based garbage collectors are favored because they are both reliable and efficient.

Heap-overflow problems often occur because of self-references. In other words, a chain of objects exists such that all of them refer to each other, so the reference-count for any of them never drops to zero.

The classical solution to this problem is to use one or more of what are called "weak references" when building the structure. These are references which do not prevent the referent from being garbage-collected. Instead, whenever the referent is reaped, the weak-references to it are "cleared."

Languages such as Java also highly-favor the notion that you should never have to build what you can simply get "off the shelf." Therefore, when you design things be sure that you're not being too clever; you're not being too manual. If there's an off-the-shelf package or class that does what you need to do, by all means use it. If you find yourself hand-building, say, "linked list" code in a system like Java, "friend, you are doing something very wrong."


All times are GMT -5. The time now is 11:53 AM.