When I play my game made with Unity on iOS device, and press the home button or let the screen close by time or by pressing the power button and then try to come back to the game, the game freezes immediately. This does not happen always, only when there's certain things happened in the game in the current session. I have found nothing in common in between these situations. If those events have not happened in the current session, I can go to home screen and play other games and come back to the game and continue where I left without issues.
I have tried debugging on xcode, with no output whatsoever in the console regarding this issue. XCode reports 200mb memory usage and Unity profiler reports roughly 300mb memory usage when going to the pause state, and nothing happens when coming back to the game. We have had memory issues previously which we have been optimizing a lot lately, but this particular crash is still persisting. Android works fine, whaterver the device memory capacity is.
I have been trying to google for this type of iOS crash, with no luck. I'm asking here if someone might have some advice or direction for me to go to.
EDIT: I updated the question to match my current situation. I previously had some code in this question and talks about memory issues, which I have found out to have nothing to do with the problem at hand.
What happens according to the debug console in XCode:
- Home button is pressed
- OnApplicationPause(true) gets called
- One Update() gets called
- GameAnalytics detects a status change (headingToBackground event) and ends session
- User is at home screen, resuming game by tapping on the game icon
- GameAnalytics gets a headingToForeground event and restarts the session
- Nothing else happens after that
This makes me want to point my finger at GameAnalytics, but why it works sometimes, just not after these specific events?