Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-03-2008, 06:45 AM   #1
Registered: Nov 2006
Distribution: xubuntu
Posts: 444

Rep: Reputation: 31
Java Heap Space

Hi there

Does anybody know how to overcome the following exception?

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at sun.misc.FloatingDecimal.dtoa(
at sun.misc.FloatingDecimal.<init>(
Old 02-03-2008, 08:38 AM   #2
Mega Man X
LQ Guru
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 64
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.
Old 02-03-2008, 01:29 PM   #3
Senior Member
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
If I remember correctly, default is 64Mb.
Old 02-05-2008, 12:15 AM   #4
LQ Guru
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 8,626
Blog Entries: 4

Rep: Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999Reputation: 2999
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."

Last edited by sundialsvcs; 02-05-2008 at 12:19 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Find Java Heap Leaks with HeapAnalyzer LXer Syndicated Linux News 0 10-20-2007 08:41 AM
Heap in nasm des_a Programming 2 06-25-2007 12:17 AM
Java process memory space 32/64 Woody Benot Red Hat 0 06-06-2007 05:07 AM
heap or stack yashwantpinge Programming 1 03-17-2006 08:25 AM
How big can Java-heap be on a 64-bit Linux betbrain Linux - Enterprise 0 08-29-2005 05:58 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:20 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration