Skip to content

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

@HarlanHugh

Description

@HarlanHugh
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions