• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Java Memory

 
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
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic