LearnNewsExamplesServices
Frontmatter
id8888
titlecore: Collection.destroy() should cleanup allItems, sorters and filters
stateClosed
labels
airefactoringcore
assigneestobiu
createdAtJan 26, 2026, 8:59 PM
updatedAtJan 26, 2026, 9:02 PM
githubUrlhttps://github.com/neomjs/neo/issues/8888
authortobiu
commentsCount1
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
blockedBy[]
blocking[]
closedAtJan 26, 2026, 9:02 PM

core: Collection.destroy() should cleanup allItems, sorters and filters

Closed v11.24.0 airefactoringcore
tobiu
tobiu commented on Jan 26, 2026, 8:59 PM

Title: core: Collection.destroy() should cleanup allItems, sorters and filters

Labels: core, refactoring, ai

Body: The current implementation of Collection.destroy() only clears _items and map. It should also:

  1. Destroy allItems if it exists.
  2. Destroy sorters and filters instances if they exist (they are typically instances of Neo.collection.Sorter and Neo.collection.Filter).

Proposed change:

    /**
     * Clears the map & items array before the super call
     */
    destroy() {
        let me = this;

        me.allItems?.destroy();

        me.filters?.forEach(item => {
            if (item.destroy) {
                item.destroy()
            }
        });

        me.sorters?.forEach(item => {
             if (item.destroy) {
                item.destroy()
            }
        });

        me._items.splice(0, me._items.length);
        me.map.clear();

        super.destroy()
    }
tobiu added the ai label on Jan 26, 2026, 8:59 PM
tobiu added the refactoring label on Jan 26, 2026, 8:59 PM
tobiu added the core label on Jan 26, 2026, 8:59 PM
tobiu referenced in commit 4b7cfae - "core: Collection.destroy() should cleanup allItems, sorters and filters (#8888)" on Jan 26, 2026, 9:02 PM
tobiu assigned to @tobiu on Jan 26, 2026, 9:02 PM
tobiu
tobiu Jan 26, 2026, 9:02 PM

Input from Gemini 3 Pro:

✦ I have implemented the requested cleanup logic in Collection.destroy().

Changes in src/collection/Base.mjs:

  1. allItems Cleanup: Added me.allItems?.destroy().
  2. filters Cleanup: Added me.filters?.forEach(item => item?.destroy()).
  3. sorters Cleanup: Added me.sorters?.forEach(item => item?.destroy()).

I used the optional chaining operator item?.destroy() inside the loops as requested for maximum safety.

Verification: Running npm run test-unit -- collection/Base confirms that the changes do not introduce any regressions.

tobiu closed this issue on Jan 26, 2026, 9:02 PM