Electron.WindowManager.BrowserWindows retains references to destroyed windows after Close() is called #1050

Open
opened 2026-01-29 16:56:36 +00:00 by claunia · 0 comments
Owner

Originally created by @HarlanHugh on GitHub (Jan 15, 2026).

  • Version: 0.4.0
  • net9.0

Description

When a BrowserWindow is closed via window.Close(), the window is destroyed on the Electron side, but the BrowserWindow object remains in the Electron.WindowManager.BrowserWindows collection. This causes errors when subsequently iterating or accessing windows in the collection.

Steps to Reproduce

  1. Create multiple windows using Electron.WindowManager.CreateWindowAsync()
  2. Close one or more windows using window.Close()
  3. Later, iterate over Electron.WindowManager.BrowserWindows and call any method on the windows

Expected Behavior

Closed/destroyed windows should be automatically removed from Electron.WindowManager.BrowserWindows, or there should be a way to detect destroyed windows before accessing them.

Actual Behavior

The collection retains stale BrowserWindow references. Attempting to call methods on these destroyed windows results in:

Uncaught exception: TypeError: Object has been destroyed
at Socket. (....electron\api\browserWindows.js:259:27)

Suggested Fix

Subscribe to Electron's closed event and remove the window from BrowserWindows when it fires

Originally created by @HarlanHugh on GitHub (Jan 15, 2026). <!-- Please search existing issues to avoid creating duplicates. --> <!-- Which version of Electron.NET CLI and API are you using? --> <!-- Please always try to use latest version before report. --> * **Version**: 0.4.0 <!-- Which version of .NET Core and Node.js are you using (if applicable)? --> <!-- What target are you building for? --> * net9.0 <!-- Enter your issue details below this comment. --> <!-- If you want, you can donate to increase issue priority (https://donorbox.org/electron-net) --> Description When a BrowserWindow is closed via window.Close(), the window is destroyed on the Electron side, but the BrowserWindow object remains in the Electron.WindowManager.BrowserWindows collection. This causes errors when subsequently iterating or accessing windows in the collection. Steps to Reproduce 1. Create multiple windows using Electron.WindowManager.CreateWindowAsync() 2. Close one or more windows using window.Close() 3. Later, iterate over Electron.WindowManager.BrowserWindows and call any method on the windows Expected Behavior Closed/destroyed windows should be automatically removed from Electron.WindowManager.BrowserWindows, or there should be a way to detect destroyed windows before accessing them. Actual Behavior The collection retains stale BrowserWindow references. Attempting to call methods on these destroyed windows results in: Uncaught exception: TypeError: Object has been destroyed at Socket.<anonymous> (...\.electron\api\browserWindows.js:259:27) Suggested Fix Subscribe to Electron's closed event and remove the window from BrowserWindows when it fires
claunia added the bug label 2026-01-29 16:56:36 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#1050