Process

Tracking Down Memory Crashes on iOS in Unity

Your game quits on iPhone with no stack trace. It is probably iOS ending the app for using too much memory. Here is how to confirm it, find the cause, and fix it.

Vectra Play 5 min read
An iPhone connected by cable to a laptop showing a memory profiler graph in Xcode

A Unity iOS memory crash usually is not a crash at all. iOS ends the app when it uses too much memory, so there is no Unity exception and often no stack trace. To fix it, confirm it was a memory kill, measure real memory in Xcode, find the largest assets with Unity's Memory Profiler, then cut textures, audio and leaks.

Step 1: confirm it is a memory kill

When iOS runs short on memory, its system watchdog, often called jetsam, ends the biggest app. From the player's side the game simply closes. Before you chase code bugs, check that this is what happened.

  1. Run a development build from Xcode on a real device. If memory is the cause, Xcode usually reports the app was terminated due to a memory issue.
  2. On the device, open Settings, then Privacy & Security, then Analytics & Improvements, then Analytics Data. Look for files starting with JetsamEvent around the time of the crash.
  3. If you see a normal crash log with a Unity or IL2CPP stack instead, it is a code crash. Debug that separately.

Test on the oldest device you support. Older iPhones have less memory, and the limit an app can use is lower than the device total.

Step 2: measure memory where it counts

The Unity Profiler in the Editor does not show you true device memory. Use the device.

Take one snapshot in the main menu, one mid-level, and one after returning to the menu. If the third is much larger than the first, something is not being released.

Step 3: find the usual suspects

Most iOS memory problems in mobile Unity games come from a short list. Sort the Memory Profiler's all-objects view by size and check these first.

SuspectWhat to look forTypical fix
TexturesLarge sizes, Read/Write enabled, no compressionASTC compression, lower max size, disable Read/Write
AudioLong music loaded as Decompress On LoadSet to Streaming or Compressed In Memory
Atlases and UIHuge sprite atlases loaded all at onceSplit atlases by screen
Leaked scenesOld scene objects still in memoryUnload assets after scene change
Static listsCaches that only growClear them on scene exit

Textures are usually the biggest lever. A 2048 by 2048 texture with Read/Write enabled keeps an extra copy in CPU memory. If you do not read pixels from code, turn it off in the texture import settings.

Step 4: fix texture and audio settings in bulk

Changing hundreds of import settings by hand is slow. An AssetPostprocessor applies rules automatically to everything in a folder.

using UnityEditor;

public class IosTextureRules : AssetPostprocessor
{
    void OnPreprocessTexture()
    {
        var ti = (TextureImporter)assetImporter;
        ti.isReadable = false;
        var ios = ti.GetPlatformTextureSettings("iPhone");
        ios.overridden = true;
        ios.maxTextureSize = 1024;
        ios.format = TextureImporterFormat.ASTC_6x6;
        ti.SetPlatformTextureSettings(ios);
    }
}

Reimport the folder and compare snapshots. Adjust the max size per folder, since UI and backgrounds may need more than props. For audio, set music clips to Streaming in the import settings for the iOS platform.

Step 5: release what you no longer need

Unity does not always free assets just because a scene changed. If you load additively or keep references in static fields, assets stay alive. After a big scene change, call Resources.UnloadUnusedAssets and make sure nothing static points at old objects.

IEnumerator SwitchLevel(string next)
{
    yield return SceneManager.LoadSceneAsync(next);
    yield return Resources.UnloadUnusedAssets();
}

If you use Addressables, every load needs a matching Release. A missing release is one of the most common leaks. Our post comparing Addressables and Asset Bundles covers the handle lifecycle.

Step 6: react when iOS warns you

iOS sends a low memory warning before it ends the app. Unity exposes this through the Application.lowMemory event. Use it to drop caches you can rebuild.

void OnEnable() => Application.lowMemory += OnLowMemory;
void OnDisable() => Application.lowMemory -= OnLowMemory;

void OnLowMemory()
{
    iconCache.Clear();
    Resources.UnloadUnusedAssets();
}

This is a safety net, not a fix. If you hit the warning in normal play, your baseline is too high.

Find your peak memory on the oldest supported iPhone, then aim to stay well below it with room for the OS and ads.

What we would do

We would reproduce on the oldest supported device first and confirm the jetsam log. Then we would take three Memory Profiler snapshots and fix the top five items by size, which is often textures and audio.

We would add the AssetPostprocessor so new assets cannot slip back in at full size, and add a memory check to the release checklist. Ads SDKs also use memory, so we would test with ads enabled, not just in a clean build.

The short version

If your iOS build is stuck on memory before a deadline, we can help.

Related reading: How to reduce Unity build size, Unity mobile performance on low-end Android, Debug frame drops on Android fast

#Unity#iOS#Development#QA#Tools
Your turn

Got a game idea? We build it.

You bring the concept. We design, build, test and launch it, and you own 100% of the finished game.

Share Your Game Idea  →