LearnNewsExamplesServices
Frontmatter
id9468
titleFix memory leak in TreeStore.#rebuildKeysAndCount()
stateClosed
labels
bugai
assigneestobiu
createdAtMar 13, 2026, 4:12 PM
updatedAtMar 13, 2026, 4:19 PM
githubUrlhttps://github.com/neomjs/neo/issues/9468
authortobiu
commentsCount0
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtMar 13, 2026, 4:19 PM

Fix memory leak in TreeStore.#rebuildKeysAndCount()

Closed v12.1.0 bugai
tobiu
tobiu commented on Mar 13, 2026, 4:12 PM

Bug Description

In TreeStore.#rebuildKeysAndCount(), an array _keys is allocated and assigned to the store instance (me._keys = new Array(len)). This array is only used locally within this method to populate the internal map and is never read or used anywhere else in the Collection or TreeStore lifecycle. Because it is bound to the instance, it persists indefinitely, causing an unnecessary memory leak that grows with every bulk projection (like expandAll or filter).

Solution

Remove the assignment to me._keys and use a local variable instead to prevent the memory leak.

    #rebuildKeysAndCount() {
        let me    = this,
            items = me._items,
            len   = items.length,
            keys  = new Array(len),
            {map} = me;

        map.clear();

        for (let i = 0; i < len; i++) {
            let key = me.getKey(items[i]);
            keys[i] = key;
            map.set(key, items[i])
        }

        me.count = len
    }
tobiu added the bug label on Mar 13, 2026, 4:12 PM
tobiu added the ai label on Mar 13, 2026, 4:12 PM
tobiu referenced in commit b55b422 - "fix(TreeStore): Remove memory leak in #rebuildKeysAndCount (#9468) on Mar 13, 2026, 4:16 PM
tobiu assigned to @tobiu on Mar 13, 2026, 4:17 PM
tobiu closed this issue on Mar 13, 2026, 4:19 PM