Skip to content

grouped-window-list: Fix store disconnect() skipping listeners - #14061

Open
somedev7 wants to merge 1 commit into
linuxmint:masterfrom
somedev7:gwl-store-disconnect
Open

somedev7 wants to merge 1 commit into
linuxmint:masterfrom
somedev7:gwl-store-disconnect

Conversation

@somedev7

Copy link
Copy Markdown

Problem

createStore().disconnect(id) iterates forward over listeners and splice()s every match. One connect({a, b}) registers two listeners with the same id. After the first one is removed, the second shifts into index i and the loop skips it, so the listener for the second key is never removed.

WindowThumbnail connects {scrollActive, thumbnailCloseButtonOffset} to the applet-wide state, so every destroyed thumbnail stays referenced from the applet's listener list forever: the thumbnailCloseButtonOffset closure keeps the thumbnail and everything it references alive. The same happens to other multi-key connect() calls on groupState for as long as the app group lives.

Impact

Found while investigating periodic desktop stutter on Linux Mint 22.3 / Cinnamon 6.6.9 / cjs 115.1. After 33 days of uptime the live JS heap (imports.system.dumpMemoryInfo() → gcBytes) was 329 MB. Since cjs schedules a non-incremental "big hammer" GC on toggle-down, which on a live desktop fires every ~10 s, the compositor was blocked 200–234 ms every 10 s (a forced imports.system.gc() took 215 ms). After restarting Cinnamon: 6 MB heap, 7 ms GC. A heap dump showed several leaks; the biggest one is #13956 (fix in #13958), this is another one.

The heap dump after 33 days had 4,246 live thumbnailCloseButtonOffset closures, all held through the store's listener list.

Reproduce

In Looking Glass:

let ap = imports.ui.appletManager.getRunningInstancesForUuid('grouped-window-list@cinnamon.org')[0];
let fired = 0;
let id = ap.state.connect({testA: () => fired++, testB: () => fired++});
ap.state.disconnect(id);
ap.state.set({testA: 1, testB: 1});
fired  // 1 without the fix, 0 with it

Fix

Iterate backwards. Verified on 6.6.9 by running the applet with this change: the snippet above returns 0, and the window list works normally.

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant