I’m using the “new” Memory Profiler to check for leaks in a game project. When I use the Memory Profiler in Diff mode, I notice that Cinemachine components always appear in the New category, never in the Deleted category. This suggests that allocations may be being made which are never freed - a leak.
I have reproduced this in a small test project. I can post this project somewhere if it would be helpful. Here is a description.
Import the Cinemachine and Memory Profiler packages using the Package Manager.
Create a new script named MainController as follows:
public class MainController : MonoBehaviour
{
private void Awake()
{
DontDestroyOnLoad(this.gameObject);
}
private void Start()
{
StartCoroutine(DoTest());
}
private IEnumerator DoTest()
{
while (true)
{
SceneManager.LoadScene("Empty", LoadSceneMode.Single);
while (!Input.GetKeyDown(KeyCode.Space))
{
yield return null;
}
Debug.Log("Running test...");
SceneManager.LoadScene("ActiveCamera", LoadSceneMode.Single);
yield return new WaitForSeconds(3.0f);
Debug.Log("Test complete");
}
}
}
Create a scene named BootScene, with a single GameObject which has a Main Controller, a Cinemachine Brain and a Camera.
Create another completely empty scene named “Empty”.
Create a third scene named “ActiveCamera”, with one or more GameObjects with CinemachineVirtualCameras.
Add the three scenes to Build Settings.
Open BootScene in the editor and enter Play mode.
Press Space to start the test. Wait for “Test complete” to appear in the console.
Open the Memory Profiler and capture a snapshot.
Focus the Game window and press Space to run another test. Wait for “Test complete” again. Repeat several times.
Capture a second snapshot in the Memory Profiler.
Open the two snapshots in the Memory Profiler and press the Diff button.
Select the Diff column header and choose Group. Select the Data Type column and choose Group. Select the Type column and Sort Ascending.
Expand New - Managed Object. Note that there is a Cinemachine.CinemachineVirtualCamera entry for each virtual camera, for each time the test was run.
Expand Deleted - Managed Object. Note that there are no entries for Cinemachine.
Unity 2019.1.14f1, Cinemachine 2.3.4, Memory Profiler preview.7 - 0.1.0.
Am I doing something wrong? Is the Memory Profiler reporting something incorrectly? Is this a genuine leak?
Cheers, Ed