0

I am currently working on a 2D java game which utilizes a linkedhashmap for rendering data at a particular tile. When I serialize the class object which contains this as well as a few other non transient objects used for map rendering the file which is output only has a size of 4kb. To my understanding RAM usage depends upon the size of whatever is being read from, but apparently I am using up a max of 20% of my memory reading from a file that is less than 4kb in size. This leads me to believe that my understanding of how RAM works is wrong or I am missing something that is giving me bad RAM readings.

Method of RAM Analysis

usedPercent = (double) (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / Runtime.getRuntime().maxMemory();
StoneAgeCoder
  • 923
  • 1
  • 7
  • 13

1 Answers1

4

The piece you are missing is that the Java Runtime Environment grabs memory to manage for itself, this includes class-path loading, intern caches, process space, stack and heap and permgen space.

Basically, as a Java developer you aren't responsible for memory management and Java does not provide tools to enable you to perform memory management.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • Does the fact that the file that is output is so small mean that I am doing something right and I should ignore the fact that the memory output to the screen is varied between 10-20%. Or does it have something to do with file compression during serialization or something? – StoneAgeCoder Dec 26 '14 at 04:52
  • 1
    I'm saying the memory usage isn't relevant to your file size, the JVM is, in and of itself, dynamic. The important thing is that you verify your instance is deserializing to your initial value. – Elliott Frisch Dec 26 '14 at 04:56
  • 1
    @ElliottFrisch - I wonder if it actually makes sense to *bank on* memory usage statistics provided by the JVM?. – TheLostMind Dec 26 '14 at 05:11