Why am I getting java.lang.outOfMemoryError on the line
va[f].normals[index] = new CVector3();
in
numverts = header.num_tris * 3; int index; FloatBuffer va2 = FloatBuffer.allocate( numverts * (3 + 2 + 3) ); float temp; int f; CVector3 normal = new CVector3(); CVector3 tri[] = new CVector3[3]; tri[0] = new CVector3(); tri[1] = new CVector3(); tri[2] = new CVector3(); CVertexArray va[] = new CVertexArray[ header.num_frames ]; for(f=0; f<header.num_frames; f++) { va[f] = new CVertexArray(); va[f].numverts = numverts; va[f].vertices = new CVector3[ numverts ]; va[f].texcoords = new CVector2[ numverts ]; va[f].normals = new CVector3[ numverts ]; for (i = 0; i < header.num_tris; ++i) { for (j = 0; j < 3; ++j) { index = i*3 + j; va[f].vertices[index] = new CVector3(); va[f].texcoords[index] = new CVector2(); va[f].normals[index] = new CVector3(); } } } vertexArrays = va;
It doesn't happen if I comment out any of the other lines
va[f].vertices = new CVector3[ numverts ]; va[f].texcoords = new CVector2[ numverts ]; va[f].normals = new CVector3[ numverts ];
It's the 6th model loaded and
header.num_frames = 260
numverts = 702
Before the stack trace it says:
This works fine on the iphone in C++/ObjC03-25 08:33:21.510: I/dalvikvm-heap(22950): Clamp target GC heap from 103.874MB to 96.000MB
03-25 08:33:22.158: I/dalvikvm-heap(22950): Clamp target GC heap from 103.987MB to 96.000MB
03-25 08:33:22.814: I/dalvikvm-heap(22950): Clamp target GC heap from 103.987MB to 96.000MB
03-25 08:33:22.814: I/dalvikvm-heap(22950): Forcing collection of SoftReferences for 20-byte allocation
03-25 08:33:23.447: I/dalvikvm-heap(22950): Clamp target GC heap from 103.987MB to 96.000MB
03-25 08:33:23.455: E/dalvikvm-heap(22950): Out of memory on a 20-byte allocation.
--- Update ---
Agh, I have to port it to NDK because you can't get around the heap memory limit in Java.