mirror of
https://github.com/electron/electron.git
synced 2026-05-02 03:00:22 -04:00
PowerMonitor registered OS-level callbacks (HWND UserData and WTS/suspend notifications on Windows, shutdown handler and lock-screen observer on macOS) but never cleaned them up in its destructor. The JS layer also only held the native object in a closure-local variable, allowing GC to reclaim it while those registrations still referenced freed memory. Retain the native PowerMonitor at module level in power-monitor.ts so it cannot be garbage-collected. Add DestroyPlatformSpecificMonitors() to properly tear down OS registrations on destruction: on Windows, unregister WTS and suspend notifications, clear GWLP_USERDATA, and destroy the HWND; on macOS, remove the emitter from the global MacLockMonitor and reset the Browser shutdown handler. Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>