Page MenuHomeFeedback Tracker

Object is not cleared - despite there is no actual strong refs for it.
New, NormalPublic

Description

When using JsonSerializer (probably in conjunction with ScriptCaller?), deserialized objects don't get destructed (even when there are no strong ref at all).

Details

Severity
None
Resolution
Open
Reproducibility
N/A
Operating System
Windows 11 x64
Category
General
Steps To Reproduce
class MyModule {

    ref MyApiClient m_ApiClient = new MyApiClient();
    ref array<ref MyApiData> m_ApiData; // Data written here don't get destrcuted


    // Can be called multiple times
    void OnModuleReady() {
        m_ApiClient.LoadData(ScriptCaller.Create(OnLoadData))
    }

    // Can be called multiple times because of ^
    void OnLoadMarkers(MyRestCallbackResult result) {
        if (result.IsSuccess()) {
            // Everything written with serializer to m_ApiData don't destructed until i manually do that like this: 
            if (m_ApiData && m_ApiData.Count() > 0)
            {
                foreach (MyApiData data : m_ApiData)
                {
                    delete data;
                }
            }
            // m_ApiData.Clear() - not helping, only delete

            string error;
            if (m_ApiClient.GetSerializer().ReadFromString(m_ApiData, result.GetData(), error)) {
                MyLogger.LogError(error);
                return;
            }
        }
    }
}
class MyApiData {

    // i can even remove ref here, and inside array - this won't get destroyed
    ref array<ref MyApiData> SubData;

    // And even SubData don't destructs, until i do that:
    void ~MyApiData() {
        if (SubData) {
            foreach (MyApiData data : SubData)
            {
                delete data;
            }
        }
    }
}

Watch attached PBO. And watch for logs. Only manually deleted objects get destructed, even when parent object get destructed - it childs remains, until we manually destruct them too.

Link: https://mega.nz/file/dkpkGBID#DqBL72CVNPfOZHM5cCFLBVeb8hp_WIcjxunmUYnMykY

Additional Information

API example response, in case temp webhook used in pbo is not availiable anymore:

[
    {
        "id": "67d1ab88a7fcaf727c5d9e4e",
        "name": "#STR_EDGE_PERSONAL_MARKERS_ROOT",
        "canEdit": true,
        "subGroups": [
            {
                "id": "67d3090c40663f5781f21bdb",
                "name": "Good marks",
                "canEdit": true,
                "subGroups": [
                    {
                        "id": "67d3094040663f5781f21c08",
                        "name": "For partially good",
                        "canEdit": true,
                        "subGroups": []
                    },
                    {
                        "id": "67d3094a40663f5781f21c11",
                        "name": "For completely good",
                        "canEdit": true,
                        "subGroups": []
                    }
                ]
            },
            {
                "id": "67d3091240663f5781f21be3",
                "name": "For a bad guys",
                "canEdit": true,
                "markers": [],
                "subGroups": []
            },
            {
                "id": "67d3091640663f5781f21beb",
                "name": "For neutrals",
                "canEdit": true,
                "markers": [],
                "subGroups": []
            },
            {
                "id": "67d3091d40663f5781f21bf3",
                "name": "Do not open",
                "canEdit": true,
                "markers": [],
                "subGroups": []
            },
            {
                "id": "67d3092340663f5781f21bfb",
                "name": "Why is it here???",
                "canEdit": true,
                "markers": [],
                "subGroups": []
            }
        ]
    },
    {
        "id": "67d1ab88a7fcaf727c5d9e4a",
        "name": "#STR_EDGE_SERVER_MARKERS_ROOT",
        "canEdit": false,
        "markers": [],
        "subGroups": []
    }
]

DayZ 1.27.159.420

Event Timeline

onemantooo edited Additional Information. (Show Details)Sun, Mar 16, 6:23 AM
onemantooo edited Additional Information. (Show Details)
onemantooo edited Additional Information. (Show Details)Sun, Mar 16, 6:26 AM
onemantooo edited Additional Information. (Show Details)Sun, Mar 16, 6:33 AM

Well. Figured it out. JsonSerializer seems to silentrly create strong ref inside of it. If we change m_ApiClient.GetSerializer() -> new JsonSerializer(). It works as expected.