Notion Electron Client and Web UI: Memory Leakage at Integration Boundary
0 reputation · 15 Aug 2022, 00:12 UTC
0 reputation · 15 Aug 2022, 00:12 UTC
The Notion desktop application utilizes an Electron wrapper to render the web-based interface. While the standalone web client maintains stable memory profiles within a browser sandbox, the desktop client exhibits progressive RAM consumption during extended sessions, particularly when rendering embedded external content or third-party integrations.
Maintaining real-time synchronization between the Electron main process and the web UI is critical for collaborative editing. There is uncertainty regarding how garbage collection is handled at the boundary between the Electron process and the embedded web components, specifically whether retained references in the wrapper prevent the web UI from releasing memory.
33775 reputation · 15 Aug 2022, 06:50 UTC
The Electron wrapper can interfere with the web UI's native garbage collection if the main process retains active references to BrowserWindow or webContents objects. There is no native Electron mechanism that automatically prevents state synchronization from creating persistent memory references; memory management at the IPC boundary must be handled explicitly by the application developer.
Established Electron Behavior: A BrowserWindow typically disposes of its webContents only when the window is closed. Navigating to a different URL or replacing embedded content within a session does not automatically destroy the renderer context or clear the associated heap. If the main process stores a reference to a window in a global variable or registers an ipcMain listener without a corresponding removal, the renderer's memory may remain reachable from the main process, blocking garbage collection (GC).
Likely Explanation (Pending Verification): The progressive RAM growth observed during the rendering of embedded external content suggests a leak at the integration boundary. This often occurs when webview elements or iframes are used; if the main process maintains a handle to these elements or their webContents, the memory allocated for that embedded session cannot be reclaimed. Additionally, third-party integration scripts may create closures that hold references to the renderer's global object, preventing the browser sandbox from releasing memory even if the Electron wrapper attempts a cleanup.
To determine if the main process is blocking the renderer's GC, the following verification steps are recommended:
--inspect) and use the Memory tab to check for multiple BrowserWindow or webContents instances that persist after the corresponding UI elements have been closed or navigated away from.ipcMain.on or webContents.on calls that lack a corresponding .removeListener() call during the window's closed or destroyed events.To refine this recommendation, please specify whether the embedded external content is implemented via <webview> tags or standard <iframe> elements. This distinction is critical because <webview> runs in a separate process with its own webContents managed by the main process, whereas iframes are managed within the renderer's own memory space.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.