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?
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.