Search Unity

Feedback Unity needs better memory hardcap detection

Discussion in 'iOS and tvOS' started by KingKRoecks, Jun 18, 2022.

  1. KingKRoecks

    KingKRoecks

    Joined:
    Jul 28, 2013
    Posts:
    155
    I recently burned multiple days, as well as new investitures of software, tracking down a bug.

    When building for iOS, there is a hard cap at 700mb of memory at runtime. If you exceed this, the app crashes.
    This is a fact. When you hit 700mb, the app will exit.

    If you are relying solely on Unity logs to tell you why the crash happened, you are out of luck.
    I went so far as to clone the netcode for gameobjects git repo into my project to debug, because I thought maybe it was some serialization issue and it only happened when I added something to my data.

    Nope.
    For some reason, when building for iOS, Unity's compression fails at runtime and iOS throws errors like this:
    Code (CSharp):
    1. WARNING: RGBA Compressed ASTC8X8 sRGB format is not supported, decompressing texture
    This happens for virtually every texture in the game. So if the texture compression goes away, the assumption is that your textures are going to literally blow up your heap.

    And that's what happens. You load a few things into memory, bam, your game crashes.

    Unity should be up to date on the targets it supports and be able to tell you about these limitations, if not build defensive mechanisms in place to avoid the chance.

    If I were building directly on a mac, I might have been able to see this in system logs. Since I was debugging an app locally but the app was built on a mac remotely, I didn't have that option and had to rely on in-game logs alone until I purchased an asset that let me see iOS logs on windows.

    So TL;DR-
    iOS has a memory limit of 700mb and force quits your app when you hit it.
    Unity should detect the memory it's allocating and build in preventative measures or at least inform the user when they hit this.
     
  2. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    Were you testing on a 1GB RAM device? On 3GB RAM device Jetsam kicks in at around 2GB and force a crash. Still, the Jetsam threshold is judged dynamically, so it’s never common to have a hard coded memory threshold in iOS apps. In C# script you can subscribe to Application.lowMemory event to monitor and act when iOS notifies your app about a low memory warning

    If your device is using A7 chip, then it does not have ASTC texture support. The best bet is to change the compression method to PVRTC. Alternatively, you can use ETC2 if you only need to support A7 and up.