Out of memory in Java heapspace?

java.lang.OutOfMemoryError: Java heap space



Following the tutorial, I started messing around.



I ended up tesselating the sphere to an insane value.

However, why would Java run out of heap space because of my 10 trillion polygone sphere?



I wouldn’t be complaining if I were getting 0.00000000001fps but Java running out of heap sapce is ridiculous.


Box b[];
   
   
   private Main()
   {
      b = new Box[9];
   }
   
   public static void main( String[] args )
   {
      Main main = new Main();
      
      main.setDialogBehaviour(SimpleGame.NEVER_SHOW_PROPS_DIALOG);
      main.start();
   }

   protected void simpleInitGame()
   {
      b[0] = new Box( "ass", new Vector3f(0, 0, 0), new Vector3f(1, 1, 1) );
      //add and update model boundary
      b[0].setModelBound( new BoundingSphere() );
      b[0].updateModelBound();
      
      //translate
      b[0].setLocalTranslation( new Vector3f(0, 2, 0) );
      
      //add colour
      b[0].setSolidColor( new ColorRGBA( 0.5f, 0.36f, 0.4f, 0f ) );
      
      Sphere sp = new Sphere( "circle shit", 1000, 1000, 1f );
      sp.setModelBound( new BoundingBox() );
      sp.updateModelBound();
      sp.setRandomColors();
      
      Node n = new Node("asss");
      
      n.attachChild(b[0]);
      n.attachChild(sp);
      
      n.setLocalScale(5);
      
      lightState.detachAll();
      
      rootNode.attachChild(n);
   }

You can adjust the minimum and maximum heap size of the VM by invoking the

java command with flags -Xms=128m -Xmx128m to allocate 128m of heap space

Also you ca use maxmem in ant.

e.g.

<java classname="MyClass"
            maxmemory="128m"
               fork="yes">
               <jvmarg value="-Djava.library.path=./lib"/>
               <classpath refid="run.class.path"/>
         </java>

Well, the JVM memory allocation is a pretty hard ceiling. Unlike the OS which can allocate more memory from the system, JVM just dumps when you reach that ceiling.

I realise that I can manually increase size but I have 2 questions:



How do polygons influence the Java’s heap space? Unless all poly data is stored in system memory instead of vram.



Shouldn’t Java automatically increase memory size as needed?



Thanks for the replies.

"K.I.L.E.R" wrote:
How do polygons influence the Java's heap space? Unless all poly data is stored in system memory instead of vram.
Well, actually, they are Java objects, aren't they? So they get stored in the JVM heap.
"K.I.L.E.R" wrote:
Shouldn't Java automatically increase memory size as needed?
It does - up to the upper limit. Then it more or less invokes the GC. If this doesn't help, it complains and quits.

That's why you can specify the upper limit for the heap. In server applications this is a fine method to control how often gc is happening, btw.
Well, actually, they are Java objects, aren't they? So they get stored in the JVM heap.


So there are 2 copies of pixel data? 1 for the video card and another for collision detection and stuff inside system ram?

well, the scene graph are made up of spatials. They contain multiple things, one of which is buffer data that is sent to the graphics cards, there are other items required that aren’t used for straight rendering functions. Scene manangement and the like.

Read you question closer, and realized you were asking about something completely different. :slight_smile:



Vector3f is an object that represents every vertex in a model. It’s a java object. These are used to build the buffers that’s sent to the card, but the objects are kept for other things not related to rendering.

Ahhh crap.



XD



Thanks, I can’t believe I didn’t see that.



I’m storing way too much information about the object.



I thought it was funny when I used values of 300, 300 for the tessellation I was getting around 10-20fps. XD



So if I were to not store the data in Java (only in vram) it would be alright (actually I would run out of VRAM and the program would crash anyway, I only have a 128MB card and if my system memory can’t hold it then there’s no chance my card could).



1GB System ram here.