From 5d82ae5efbc012fcbbd4938e37959277f3356318 Mon Sep 17 00:00:00 2001 From: iFwu <16523864+iFwu@users.noreply.github.com> Date: Sat, 21 Nov 2026 02:01:20 +0900 Subject: [PATCH] test(core): cover a rebuilt tooltip freeing the view it replaced A view rebuilt with its tooltip used to leave the old bubble in the root view's hosted list, which kept the old view, its text layouts and its bindings for the life of the window. main now takes a discarded hoisted node out of its host's list (9b726da7b); this adds a regression test for the rebuilt-tooltip case and the changelog entry for #1006. Fixes #1006 --- CHANGELOG.md | 1 + core/tooltip_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bdba4a16..2a2985e28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -131,6 +131,7 @@ - Free a removed `EdgeBar` view and a removed scroll view a bar was over, instead of the lists of bars and of the scroll views they reach into keeping them past their new end, and through each the whole subtree it was in, while another bar stays (#1023 by @iFwu). - Land a `List`'s scroll to a row, or to its end, where it asks when rows were inserted, removed or measured above the viewport in the same update, instead of shifted by the scroll that would have kept the visible rows in place (#1019 by @iFwu). - Pull a scroll view's offset back to its end in `nsgotest` when its content shrinks or its viewport grows past it, and report where it went, as macOS, Windows, Linux, Android and the web do, instead of leaving it past the end (#1020 by @iFwu). +- Free a removed `Overlay`, `Modal`, `Position: Fixed` view or `Tooltip` bubble instead of the view hosting it keeping it, and through it the whole subtree it was in, for the life of the window, so rebuilding a view with a tooltip no longer grows memory (#1006 by @iFwu). ## [0.2.0] - 2026-11-19 diff --git a/core/tooltip_test.go b/core/tooltip_test.go index 4924de357..f5323495d 100644 --- a/core/tooltip_test.go +++ b/core/tooltip_test.go @@ -1,7 +1,10 @@ package core import ( + "fmt" + goruntime "runtime" "testing" + "weak" "github.com/nsgo-dev/nsgo/internal/driver" ) @@ -128,3 +131,27 @@ func TestHiddenTooltipDoesNotFollowScrolls(t *testing.T) { t.Fatal("a shown tooltip does not follow a scroll") } } + +// A view rebuilt with its tooltip leaves nothing of the old one behind: the root view hosts only the shown copy's overlay, and the old view and what was in it are freed. +func TestRebuiltTooltipFreesTheOldView(t *testing.T) { + var rev *Signal[int] + h := newHost(t, Size{Width: 300, Height: 300}, func(cx *Scope) Node { + rev = NewSignal(cx, 0) + return Dynamic(func(*Scope) Node { + return View{TestID: fmt.Sprint("trigger", rev.Get()), Label: "Save", Role: RoleButton, Tooltip: Text{Content: "Writes the document"}} + }) + }) + h.commit() + old := weak.Make(h.find("trigger0")) + for i := 1; i <= 3; i++ { + rev.Set(i) + h.commit() + } + if n := len(h.tree.view.hosted); n != 1 { + t.Fatalf("the root view hosts %d overlays, want the shown tooltip's 1", n) + } + goruntime.GC() + if old.Value() != nil { + t.Fatal("the view rebuilt away stays in memory") + } +}