Search Issue Tracker
Fixed
Fixed in 2022.3.26f1, 2023.3.0b3, 7000.0.0a1
Votes
0
Found in
2022.3.22f1
2023.3.0a15
7000.0.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
- [HDRP] Empty template starts with incorrect Physically Based Sky ground
- Big chunk of "Untracked" memory in the Memory Profiler screenshot when a custom .obj file is loaded while in Play Mode
- Video contains artifacts when played in the Video Preview section in the Inspector Window
- UI Toolkit Slider "Fill" option doesn't invert when "Inverted" option is selected
- The Random Value option in the Set Attribute Block gets disabled and the "B"/"Max" value lost when upgrading to Unity 6
Resolution Note (fix version 7000.0.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.
Resolution Note (fix version 2022.3.26f1):
Bug fixed in 2022.3