Unity iOS 13 Memory leak Crash

Hello!

We have been experiencing some memory leaks on our project, and we have no clue about what is going on. It does not happen always, I’ve been trying to reproduce it but it only happens like once every few hours. There is no pattern on when it happens. I’ve tried to connect the iphone with the unity profiler and, the unity profiler does not show anything strange. But When connecting with Xcode we can see that the game starts increasing the memory until it reaches the limit and the SO closes it. (Take into account that those “steps” are only because I’ve tried to go step by step in the execution from xcode, but without pausing the execution is simply a ramp up until it crashes.

I’ve tried to connect the iPhone and use the unity profiler but unity profiler didn’t show anything strange, it showed the normal memory usage.

We are using: Adjust, Facebook, Leanplum, Amplitude, IronSource Crashlytics (this crash does not appear there, because it ran out of memory, so it cannot save/send the crash).
Unity 2019.2.13f1

I also uploaded the instruments alloc memory screenshot.


I’ve tried adding logs into Leanplum calls, and everything and I have no clue on how to solve it or which can be the problem. Anyone has faced the same problem?!

As I said, there is no pattern, sometimes simply having the game in the map menu without doing anything for few minutes and then it starts to consume a lot of memory.

I also attach: Instruments alloc screenshot.

We are using: Adjust, Facebook, Leanplum, Amplitude, IronSource Crashlytics (this crash does not appear there, because it ran out of memory, so it cannot save/send the crash).
Unity 2019.2.13f1

I’ve tried adding logs into Leanplum calls, and everything and I have no clue on how to solve it or which can be the problem.

We are having the same issue. Can’t find the source, but whenever the leak starts we see these lines in the console:

2020-04-13 10:54:16.042345+0300 coins[9258:3510682] [] tcp_input [C1.1:3] flags=[R] seq=721827828, ack=0, win=0 state=CLOSED rcv_nxt=721827828, snd_una=457955433
2020-04-13 10:54:16.042611+0300 coins[9258:3510682] [] tcp_input [C2.1:3] flags=[R.] seq=1925316496, ack=2318857751, win=117 state=CLOSED rcv_nxt=1925316456, snd_una=2318857751
2020-04-13 10:54:16.134318+0300 coins[9258:3510563] [] tcp_input [C1.1:3] flags=[R] seq=721827828, ack=0, win=0 state=CLOSED rcv_nxt=721827828, snd_una=457955433
2020-04-13 10:54:16.141155+0300 coins[9258:3510563] [] tcp_input [C2.1:3] flags=[R] seq=1925316456, ack=0, win=0 state=CLOSED rcv_nxt=1925316456, snd_una=2318857751
2020-04-13 10:54:16.498487+0300 coins[9258:3510613] [] tcp_input [C6.1:3] flags=[R] seq=1564791191, ack=0, win=0 state=CLOSED rcv_nxt=1564791191, snd_una=2431114689
2020-04-13 10:54:16.498668+0300 coins[9258:3510613] [] tcp_input [C6.1:3] flags=[R] seq=1564791191, ack=0, win=0 state=CLOSED rcv_nxt=1564791191, snd_una=2431114689

We discover that one of our http calls (post call) that was sending a lot of info, was working fine 95% of the time, but some times, the connection was not close and the memory increases like cazy.

We log the WWWConnection.mm and UnityWeRequest.mm and we found the call and after avoid this call we decrease the issue by 70%. The issue is not solved but is very clear that are internet related and httpBodyStream related.

What unity version are you using?

It should be revised as soon as possible.

In my case, memory leakage occurs when I change domain even though I am looking at the same server.

@doubletapsoft I am not sure if this will help but what I did is that I run garbage collector in some places in my code.

I had some classes which were not inherited from MonoBehaviour and they were holding huge data chunks coming from DB in HashTables. I reset those HashTables and ran garbage collectors.
Also, I changed the game architecture to create and destroy the UI prefabs based on what player clicks and manually reset/ cleared all the arrays/lists or Dictionaries that object was using. This reduced the RAM usage in game significantly.

There is one more thing you can do, you can use LZ4HC compression for iOS. Remove the unnecessary images from folders and if you have a number of images that are being used together you can create an asset bundle for them but remember to unload the asset bundle.

These steps reduced the memory usage on my side. Hop it helps.

I’ve identified a solution to address the crash issue, which was related to garbage collection.

To resolve it, I’ve implemented explicit garbage collection calls within the code, responsible for removing unused assets and references both before and after the scene loads. It’s important to use these functions in contexts where they won’t disrupt the gameplay experience. You can invoke these functions multiple times, and when you check the memory profiler in Xcode, you’ll notice a significant reduction in RAM usage.

GC.Collect();
Resources.UnloadUnusedAssets();