Question

I'm using the AssetManager class in Starling to load a lot of textures, around 600-700 png-files. All files are not loaded on start and I use multiple AssetManagers to hold the images. On start it loads around 70 images to 3 different managers and while it's loading I get some memory warnings on iOS.

  • iPhone appName[644] : Received memory warning.
  • iPhone appName[644] : Application received a memory warning from the system.
  • iPhone SpringBoard[74] : Received memory warning.
  • iPhone MobilePhone[199] : Received memory warning.

I've tried to load them at the same time and tried start each load when the other one is completed. I've also tried System.gc(); and System.pauseForGCIfCollectionImminent(0.1); between each load, this fixed the problem on iPhone 5 (7.0.4) but not on an iPhone 3gs (6.1.3).

Starling version: 1.4.1

Anyone got any tips on how to solve this?

Was it helpful?

Solution

Typically from a mobile development standpoint there is never a "one size fits all" solution. There are many different screen sizes and hardware configurations. In order to combat this many developers will generate -as mentioned previously, Sprite Sheets. Using this method the application only has to load one image vs -in your case hundreds. Image loaders take quite a while connecting to a memory address to initiate a texture upload to the GPU -I can't even image how slow it must be for that many assets.

This texture packer is phenomenal, and also aides with another feature many dev's incorporate. Asset Densities. Wherein the iPhone 3Gs a dev will load a set of sprite sheets developed for smaller screen sizes, a larger sprite sheet with twice the sized assets will load for a tablet or some of the higher end devices. This method will not only solve your memory issues but make your application look much better over a broader range of devices.

Here is a link to the Starling Wiki on multi-resolution development.

Of all the changes you can make to a project "for the better" the ones mentioned above are very high on the list.

OTHER TIPS

You should NOT be loading 600-700 images. Even if they load successfully, you'll have a lot of problems with the performance. Instead, use atlas/sprite sheets.

http://wiki.starling-framework.org/manual/textures_and_images

And for even more optimized work, use ATF Textures instead png.

http://wiki.starling-framework.org/manual/atf_textures

If you run XCode Instruments against your app you'll see the total load of the device, which is the real metric that determines how often you receive memory warnings.

If your total load % is above 80%, expect a slew of constant memory warnings. The GC will try and run every time causing drastic clipping in framerate.

There's a bug about this and Adobe is working on it, but the main solution is to simply use less memory. Downscale textures for devices that have lower resolutions, etc...

https://bugbase.adobe.com/index.cfm?event=bug&id=3649713

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top