Serialization Memory

Issue #629 resolved
UMX Studio created an issue
  1. Serialization keeps in memory after destroying scene object
  2. Reproduce Steps
  • Step 1 : Create empty scene
  • Step 2 : Create another gameplay scene
  • Step3 : Create OdinTest.cs (See bellow script)
using System;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;

public class OdinTest : SerializedMonoBehaviour
{
    public Dictionary<string,OdinPrefab> prefabs = new Dictionary<string, OdinPrefab>();
}

[Serializable]
public class OdinPrefab
{
    public GameObject demoPrefab;
}
  • Step 4 : Attach this script on one scene object under gameplay scene
  • Step 5 : Now start from empty scene and capture memory snapshot from Unity’s Memory Profiller (Nothing in memory related to OdinPrefab type) see image1
  • Step 6 : Now load gameplay scene and then capture memory snapshot ( now you see that serialization for OdinPrefab is in memory) see image2
  • Step 7 : Now go back to empty scene here expected that serialization memory cleared up from memory but after taking memory snapshot i seen that it’s serialization keeps in memory see image3

Does it is memory leak or what

3. Unity 2019.2.8f1

4. Odin 2.1.9

5. Editor mode disabled

6. OS Windows 10

Comments (1)

  1. Tor Esa Vestergaard

    Discussed this with the reporter on Discord. The screenshots indicate that everything is working as intended, as the serialized dictionary is collected in between image 2 and 3 (thus no leak there), and the rest the of the allocated memory is intended to be cached by the serializer per-type. This overall has a very light memory footprint - once you've serialized a given type once, the serializer will never allocate more caching for that type, so the growth is linear with the amount of types the serializer has seen (as can be seen in the screenshot, generally a few dozen bytes per type).

  2. Log in to comment