Image memory management

Community Forums/Monkey Talk/Image memory management

Leon Brown(Posted 2014) [#1]
Hi. I have a list of full screen sized images that should be used in an app. The problem is that iOS crashes once the memory gets used up, so I need a way to unload these images and reload them when required. I've noticed that even when loading over existing images, the memory usage still increases and so results in the app crashing because it eventually runs out of memory. I've also tried the Discard method, but that isn't helping - maybe because I'm trying to load new images into the reference I've discarded. Does anyone have any tips for this?


MikeHart(Posted 2014) [#2]
Discard actually should work. That is the purpose of it. Which version are you using? Which platform?


*(Posted 2014) [#3]
Maybe the GC isn't catching the discarded image till its to late, is there a way to force GC like in max?


Leon Brown(Posted 2014) [#4]
Thanks for your input. It appears to be a bit of an illusion (at least on iOS) because the garbage collector is only called when the device issues a memory warning notification - this then triggers the garbage collector to clear the memory. When testing an app on the iOS simulator, no memory warning is generated because the simulator sets its memory size to be the available amount of the development machine, which is much bigger than on an actual device. You can manually test garbage collection in the simulator by going to "Hardware" > "Simulator Memory Warning" from the simulator's top menu.

@Mark Sibly: It might be worth adding this to the documentation - it took me a day to figure this one out ;).


*(Posted 2014) [#5]
Ah for iOS all I can say is ALWAYS test ya game on device as the simulator is crap, when I don't ismashem galactic it all ran beautiful in the simulator to crash at start on device. As you say the simulator has waaaay more resources than a iPod (in my case I adjusted my obj c code so it only use 2mb of the 7mb available) once adjusted it will work perfectly.

In most cases coding actually in xcode and obj c made it MUCH easier to debug and sort out


Leon Brown(Posted 2014) [#6]
I've been testing on the client's iPads, but might pick up an iPod Touch to test here. Would it be better to go for a 5th generation with specs comparable for to iPhone 4/5+, or go for a 4th generation to ensure lower compatibility?