Image memory management

Monkey Forums/Monkey Programming/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?


Leon Brown(Posted 2014) [#2]
Ok, it seems that this issue is resolved (on iOS - not sure about other targets) 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 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 ;).