App crashes when I add an array of more than 200 spheres to the world

Started by CarlosMB89, December 03, 2014, 04:18:22 PM

Previous topic - Next topic

CarlosMB89

I'm creating an array of more than 200 spheres for adding them to the world, but when 200 spheres more or less are created the app crashes and this error appear ("OutOfMemory).

Do you know what is the reason?? Because it sounds strange a out of memory error for only 200 spheres.....

Thanks

EgonOlsen

Quote from: CarlosMB89 on December 03, 2014, 04:18:22 PM
Because it sounds strange a out of memory error for only 200 spheres.....
That's a bit like finding it strange that "he's dead even if i've shot him only 10 times"... ;) 200 spheres is quite a lot, not "only". Are these all visible in one frame? If not, then you might want to consider a more MVC like approach that assigns views (i.e. Object3D) to potential visible sphere beans.
Anyway, how much memory is available to the VM depends on the Android version and the vendor and it ranges from 16mb to 512mb (at least i haven't seen anything about that }or now). If your spheres are all more or less equals, don't do something like:


for (int i=0; i<200; i++) {
    spheres.add(Primitives.getSphere(10));
}


But rather work with a blueprint object to share data between objects like so:


Object3D bp=Primitives.getSphere(10);
for (int i=0; i<200; i++) {
    Object3D s=new Object3D(bp, true);
    s.shareCompiledData(bp);
    spheres.add(s);
}

CarlosMB89

Oh it works thank you very much EgonOlsen ;) ;). But I have one question....my curiosity XD... if android devices have so little memory...how does they run some games as Asphalt 8 for example, they have lots of 3D objects I suppose.

Thanks in advance

EgonOlsen

They aren't using the Android SDK (i.e. Java), but the NDK (i.e. C++), which doesn't have this limitations. However, if you need more memory inside the VM, check out the "android:largeHeap" setting for your AndroidManifest.xml