Find memory leaks
Memory leaks cause your application to perform worse over time and might lead to a crash.
Memory leaks typically happen for one of the following reasons:
- Missing code to release objects from memory.
- Unintentional references keeping objects in memory.
To identify memory leaks, capture and compare multiple snapshots. Refer to Compare two snapshots for more information.
Detect memory leaks after scene unload
Leaks often result from user-allocated objects or resources not released after a scene unload.
To identify this type of leak perform the following steps:
- Open Window > Analysis > Memory Profiler.
- Use the Attach to Player dropdown to set the source as a running Player.
- Load an empty scene and create a snapshot of it.
- Load the test scene, play partway through, then unload it or change to an empty scene. To fully unload assets, call
Resources.UnloadUnusedAssets
or load two new scenes consecutively. - Take another snapshot and optionally close the Player.
- Compare snapshots and use any of the Memory Profiler tabs to inspect the snapshots.
Increased memory usage in the second snapshot might indicate a memory leak.