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") + } +}