Skip to content

fix: widget lifecycle correctness sweep (#171, #173, #174, #175, #181, #182)#186

Merged
kolkov merged 6 commits into
mainfrom
fix/lifecycle-sweep
Jul 16, 2026
Merged

fix: widget lifecycle correctness sweep (#171, #173, #174, #175, #181, #182)#186
kolkov merged 6 commits into
mainfrom
fix/lifecycle-sweep

Conversation

@kolkov

@kolkov kolkov commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Six widget lifecycle fixes addressing memory leaks, goroutine leaks, and dead signal bindings reported by @AnyCPU from long-term macOS testing.

Fixed

Tests

28 regression tests across 5 new test files:

  • core/listview/lifecycle_test.go (5 tests)
  • core/gridview/lifecycle_test.go (4 tests)
  • app/overlay_lifecycle_test.go (7 tests)
  • app/window_close_test.go (6 tests)
  • core/linechart/safety_test.go (6 tests)

Test plan

  • go build ./... — pass
  • go test ./... -count=1 — all tests pass
  • golangci-lint run --timeout=5m — 0 issues
  • New regression tests verify each fix

kolkov added 6 commits July 16, 2026 10:25
…174)

Evicted decorators were overwritten without UnmountTree, leaking GPU
scenes and signal bindings. New decorators from Content[C].Render were
never mounted, so child signal bindings were dead.

Changes:
- cleanupWidget helper calls UnmountTree on evicted widgets
- fullRebuild/incrementalUpdate unmount old widgets before replacement
- clear() unmounts all widgets before zeroing
- buildDecorator calls MountTree after creation when ctx is available
- cache.update() now accepts widget.Context (passed from Draw)
…181)

Cell widgets from Content[C].Render were never mounted (signal bindings
dead) and never unmounted on eviction (scene/binding leak).

Changes:
- cellCache.update unmounts old widgets before rebuilding
- cellCache.clear unmounts all widgets
- New cells are mounted with MountTree when ctx is available
- cellCache.update accepts widget.Context parameter
Overlay containers were pushed/popped without mount/unmount calls,
leaking signal bindings and goroutines in content widgets.

Changes:
- PushOverlay calls MountTree on the container after pushing
- PopOverlay calls UnmountTree on the popped container
- RemoveOverlay unmounts the target and all overlays above it
  (matching overlay.Stack.Remove stack semantics)
Window had no Close method, so the animation pumper goroutine leaked
on window close, and widget trees were never unmounted.

Changes:
- Window.Close() stops animPumper, unmounts all overlays, unmounts root
- desktop.Run OnClose callback calls Window.Close before releasing GPU
- Close is idempotent (safe to call multiple times)
…fety (#182)

PushValue, AddSeries, ClearSeries called SetNeedsRedraw directly from
arbitrary goroutines. SetNeedsRedraw propagates upward through the
parent chain which is not thread-safe.

Changes:
- Add scheduler field, stored during Mount, cleared during Unmount
- requestRedraw helper routes through scheduler.MarkDirty when
  available, falls back to direct SetNeedsRedraw for unmounted usage
- Replace all SetNeedsRedraw(true) calls with requestRedraw()
- listview lifecycle_test.go: mount/unmount on scroll, eviction, clear
- gridview lifecycle_test.go: cell mount/unmount, update, invalidate
- overlay_lifecycle_test.go: push/pop lifecycle, signal bindings
- window_close_test.go: close idempotency, unmount, stop pumper
- linechart safety_test.go: concurrent PushValue, scheduler routing
- CHANGELOG v0.1.46, ROADMAP version update
@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.72727% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
core/listview/cache.go 87.50% 3 Missing and 2 partials ⚠️
core/gridview/gridview.go 93.10% 1 Missing and 1 partial ⚠️
desktop/desktop.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@kolkov
kolkov merged commit 4378109 into main Jul 16, 2026
9 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