Skip to content

Fix macOS resource leaks, events, and geometry - #192

Merged
treeform merged 9 commits into
masterfrom
fix-macos-resource-lifecycle
Sep 6, 2026
Merged

Fix macOS resource leaks, events, and geometry#192
treeform merged 9 commits into
masterfrom
fix-macos-resource-lifecycle

Conversation

@treeform

@treeform treeform commented Sep 6, 2026

Copy link
Copy Markdown
Owner

The macOS backend leaks native image and window resources, can abort when a frame callback closes a window, and mishandles queued keyboard input and window geometry. This PR fixes nine issues in nine separate commits.

  1. Release CPU frame images on replacement and close, and scope temporary Cocoa objects to an autorelease pool.
  2. Pass temporary filenames to TextEdit as process arguments, preventing shell execution and preserving spaces and quotes. Report launch failures as WindyError.
  3. Iterate a snapshot of windows during frame callbacks so closing or creating windows does not invalidate iteration. Newly created windows receive their first frame on the next poll.
  4. Balance custom cursor and cursor-image allocations after AppKit takes ownership.
  5. Balance native view and OpenGL pixel-format allocations, and remove tracking areas and retained composition text during window cleanup.
  6. Release TIFF clipboard bitmap representations on success and early return.
  7. Drain all queued keyboard and modifier events in one poll instead of stopping after the first event.
  8. Center the final native window frame in screen points, including decorated and borderless windows on Retina displays.
  9. Calculate mouse containment from unrounded content coordinates so dragging outside the window does not set mouseInside to true.

Validation on Apple Silicon macOS with Nim 2.2.10:

  • New macOS regressions pass in OpenGL and CPU builds, with checks enabled and in release mode. They cover image ownership, close/create callbacks, view and tracking-area ownership, event ordering, centering, and mouse bounds.
  • New temporary-file regression verifies argument boundaries with spaces, quotes, Unicode, and shell metacharacters. The existing openUrl regression and CPU smoke test pass.
  • Apple leaks reports zero leaks in the CPU-image, repeated custom-cursor, and repeated TIFF-read probes. TIFF tests use a private pasteboard.
  • All native examples compile. The Metal backend passes nim check.
  • CI now runs the new regression tests on macOS.

@treeform
treeform merged commit 341d083 into master Sep 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant