[ANSWERED] Memory Leak on iOS game?
Hello,
I have created a game which runs fine in the GS preview, but when I run it on my iPhone 4s through the GS viewer, it keeps crashing after a change scene. I have used Xcode Instruments to identify the issue and as expected, it is a memory issue. At its peak my game has reached 200MB of memory according to GS viewer, but usually crashes at about 120MB. I have no idea how to reduce this, because I have turned off all animation, sound, music, background movement and camera behaviours so that it is literally running the game on bare minimum, and it still reaches ridiculous memory figures and crashes! My game file I have reduced to only 6MB, but I think that it is my images which are the issue here because GS is saying that they are using up to 195.6MB of memory at their peak! I really do not understand this, can anybody help?
Thanks,
Oliver
BTW - My images are relatively large (but add up to less than 6MB because this is the file size) because I am creating a universal game for retina devices included
Comments
@olivern you need to reduce the size (dimensions ) of your images. looks like your image are taking up to much RAM.
Okay, I will try that! Thank you for replying so quickly!
Thank you - that has worked!
Hi Olivern,
We are having the exact same problem. We are building an universal app and everything works on iPad 4 and mini. When we try on iPhone 4s it crash after 2 levels.
How much did you reduce you images to in order for it work?
When we play through the first to levels everything works fine but at level 3 it crashes (native build) If we go straight to level 3 it works fine. I seems like there is a problem with memory accumulation. Any advise will be greatly appreciated:)
Thanx,
Thomas,
Copenhagen
@cph127
Ipad 4 has 1GB of RAM compared to 512 MB for Iphone 4s, since they are both retina devices they will both be using the same high res images (assuming you're using RI) thus using up the same amount of RAM. Roughly speaking you would not want to go over half the limit of the available RAM for the device. So if you see e.g. 400GB of RAM usage when testing via gs viewer or monitoring an adhoc build using xcode instruments then that will be fine for Ipad 4 but you're doomed running that version of the app on iphone 4s.
That said, what's more interesting is that you wrote that level 3 works fine if you play it directly (but not if you play level 1 and 2 first) and that memory builds up. I know exactly what you mean***. To my surprise this seems to be something completely unknown even for devs. here that I consider very skilled in many GS areas (most likely because they have not built an app that lives on "the edges of device memory" and/or that they have not tested it on the required devices or tested enough).
***The only full solution to this that I have found (assuming one already has the required knowledge of what can be done with image files in regards to how different pixel dimensions for images are allocated etc) is to destroy every actor when you are done with it and respawn when needed instead of using the fully automated behaviours. So for example, when you die in game, destroy all actors, reset all attributes and respawn the initial actors instead of using e.g. "Reset Game" which does not fully restore the RAM used.
Hej från Sverige!
Hey,
Thanx for your quick response - my fellow scandinavian game developer:)
I do really appreciate you sharing your knowledge, experiences and thoughts. Thanx again.
We haven't been building our game with an XML file (Like in unity 3D) telling every actor where to start etc. All our actors/hazards etc have a fixed starting position in every level with behaviors etc. We spawn different effects and stuff but to spawn everything is not really an option, hence then we need to change the entire game.
Or do we? D you have any suggestion of how to change from fixed position to spawns?
How would you approach it ?
Cheers,
Thomas