flutter-plugins icon indicating copy to clipboard operation
flutter-plugins copied to clipboard

[desktop_multi_window] Closing window does not free resources, when plugin is used together with window_manager

Open thomasgi1 opened this issue 2 years ago • 1 comments

When the desktop_multi_window plugin is used in combination with the window_manager plugin on MacOS, then resources are not freed, when closing a window. The reason for that is the FlutterWindow extension:

extension FlutterWindow: NSWindowDelegate {
  func windowWillClose(_ notification: Notification) {
    delegate?.onClose(windowId: windowId)
  }

  func windowShouldClose(_ sender: NSWindow) -> Bool {
    delegate?.onClose(windowId: windowId)
    return true
  }
}

which overrides the windowWillClose and windowShouldClose members. However, the window_manager plugin does the same by extending the NSWindowDelegate protocol. Since extensions cannot replace existing implementations the FlutterWindow extension has no effect, so that the delegate?.onClose() function never gets called leaving the whole isolate responsible for the closed window im memory.

Version:

  • Flutter Version: 3.13.6
  • OS: macOS 12.7
  • plugin: desktop_multi_window 0.2.0 + window_manager 0.3.6

thomasgi1 avatar Oct 08 '23 12:10 thomasgi1

I encountered the same issue.

LEggcookies avatar Mar 11 '24 09:03 LEggcookies