Shouldn't MemoryHelper.compact() Free All My RAM?

Started by AGP, December 06, 2013, 07:52:27 PM

Previous topic - Next topic

AGP

I wrote a little endless runner, which I tested with textures 512x512 in size, on both the Nexus 10 tablet and the Galaxy S4. It ran fine. On the Galaxy Tab 2, for which the game was actually written as that is my son's tablet, it doesn't run at all. I've even reduced the textures to 256x256. After loading all the textures I call MemoryHelper.compact(). But before even the first chunk of city is loaded (and during its loading process), the game crashes with an OutOfMemoryError. I would think that the model itself isn't so complex that it would crash for simply trying to load this chunk (it has a total of 36k triangles). Is it possible that compact isn't doing its job (at least not right away)? Any suggestions?

EgonOlsen

compact() doesn't do more than calling some combination of runFinalization and gc which forces the vm to free unused memory. It used to help on older devices. You should check how much memory the vm on this tab provides. Maybe its Android version already supports the large memory setting in the manifest. That exactly are you loading (3ds, obj, serialized...)?


EgonOlsen

Yes, that's the usual blahblah about System.gc();. Let's call it a strong suggestion. One that you usually can't resist...
Apart from that, this isn't needed except on some 1.x based devices that had issues with collecting unused native memory in time.

AGP

It's a serialized object. Interesting about the large memory setting. I'll look into it.

AGP

android:largeHeap="true" did it for me, thanks a lot. Is the reason that the S4 and Nexus 10 not need this that their normal heap is as large (or nearly) as the Tab 2's large heap?

EgonOlsen

Heap differs from Android version to Android version and from device to device. As a rule of thumb, one can say that it increaes with each Android version but the vendor is free to adjust it if he feels that this is needed.