Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Memory

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can someone explain how the java memory works, below is what I've got:

FREE MAX TOTAL

I added an array of 44,703,332 strings to program, and I got a 'heap space error'
Using 44,703,331 gives the TOTAL the same as the MAX.
So thats quite clear.

But my free memory is still 75M, intuitively I would have thought FREE+TOTAL = MAX
so in my example above, you would expect the FREE to be 0, but its 75M instead.

So its not as simple as I thought, can anyone explain how the 3 values relate to each other.

Thanks
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Runtime.freeMemeory() returns an approximation to the total amount of memory currently available for future allocated objects, measured in bytes.
Runtime.totalMemory() returns the total amount of memory in the Java virtual machine. The value returned by this method may vary over time, depending on the host environment.
Runtime.maxMemory() is proabaly the only 'fixed' value.

As I see it, these values correlate somewhat loosly and there is no formula for it that would work all the time (if ever).
 
Mukesh Ranjan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which exception you are getting exxactly,

Check if it OutOfMemory Exception or StackOverflowException,

If you are doing it inside some thread or if it is a local variable then try to look for stack size, rather than heap size..


For more detail you can look at site: www.pourbrain.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic