This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Memory  RSS feed

 
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
 
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).
 
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
Boost this thread!