Search Issue Tracker
In Progress
Fixed in 2023.3.0b3, 2024.1.0a1
Under Consideration for 2022.3.X
Votes
0
Found in
2022.3.22f1
2023.3.0a15
2024.1.0a1
Issue ID
UUM-55645
Regression
No
[Linux][Memory leak] entering and exiting Playmode continuously leads to memory usage up and crash
Put the following script in the Spaceship Demo asset:
https://github.com/Unity-Technologies/SpaceshipDemo
{code:java}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using Unity.Collections;
#if UNITY_EDITOR
[InitializeOnLoad]
public class NewBehaviourScript
{
static NewBehaviourScript(){
EditorApplication.update += Update;
}
// Start is called before the first frame update
void Start()
{
NativeLeakDetection.Mode = NativeLeakDetectionMode.Enabled;
}
// Update is called once per frame
static void Update()
{
if(EditorApplication.isPlaying)
{
EditorApplication.ExitPlaymode();
}
else
EditorApplication.EnterPlaymode();
}
}
#endif
{code}
This will let the editor enter and exit playmode constantly. Observe from the system monitor that the memory Unity process takes keeps increasing.
Looking in the editor log, the memory consumption each time entering and exiting playmode also climbs up:
{code:java}
AcceleratorClientConnectionCallback - disconnected - :0
Unloading 54 Unused Serialized files (Serialized files now loaded: 0)
Loaded scene 'Temp/__Backupscenes/0.backup'
Deserialize: 11.782 ms
Integration: 159.701 ms
Integration of assets: 0.018 ms
Thread Wait Time: -0.003 ms
Total Operation Time: 171.498 ms
Unloading 1126 unused Assets / (2.4 MB). Loaded Objects now: 10094.
Memory consumption went from 1.11 GB to 1.11 GB.
Total: 37.907034 ms (FindLiveObjects: 2.505118 ms CreateObjectMapping: 1.130139 ms MarkObjects: 24.541882 ms DeleteObjects: 9.724916 ms)
{code}
attached half of the editor log here and looking from the bottom up you can see that the memory consumption has been consistently going up. This eventually goes to 30GB running for a day and crash. Looking at the system log, the program is killed by oom killer on linux.
Another issue with the memory profiler that is related to this:
https://unity.slack.com/archives/C3H8JSB5E/p1699316406804749
On MacOS, the memory does not leak by entering/exiting playmode, but it does when using the memory profiler. As you could see in the snapshot, unity is claiming 60+GB memory when 4 memory snapshot and the rest is deleted.
All the incremental memory size seems coming from the native Malloc(Persisten) according to the profiler result.
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- “[Worker0] Could not generate preview image“ error when opening macOS native plugin in the Inspector with Architecture to build for set to ARM 64-bit
- [iOS] Application.absoluteURL is empty on Awake/Start when opening via deep link with Splash Screen disabled
- Crash on MemoryManager::Deallocate when rapidly calling Addressables.LoadAssetAsync
- Crash on physx::shdfnd::atomicIncrement when adjusting values on a character controller component after entering Play mode in Prefab edit mode
- [Rendering Debugger] [NewInputSystem] Debug Overlays in Play mode throws InvalidOperationException when using New Input System
Resolution Note (fix version 2024.1.0a1):
the PR landed and nightly tests with my script shows the memory leak is gone after this change.
Resolution Note (fix version 2023.3.0b3):
i ran my script overnight and the memory consumption is very consistent now. looks like the issue is gone after this fix. Thanks so much.