From f45594d2c9d50866262bc515c844147348a37c74 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 21 Mar 2024 10:47:31 -0700 Subject: [PATCH] control/controlclient: free memory on iOS before full netmap work Updates tailscale/corp#18514 Change-Id: I8d0330334b030ed8692b25549a0ee887ac6d7188 Signed-off-by: Brad Fitzpatrick --- control/controlclient/map.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/control/controlclient/map.go b/control/controlclient/map.go index 31854515f..5b7cb46d4 100644 --- a/control/controlclient/map.go +++ b/control/controlclient/map.go @@ -11,6 +11,8 @@ import ( "maps" "net" "reflect" + "runtime" + "runtime/debug" "slices" "sort" "strconv" @@ -187,6 +189,12 @@ func (ms *mapSession) HandleNonKeepAliveMapResponse(ctx context.Context, resp *t // our UpdateFullNetmap call). This is the part we tried to avoid but // some field mutations (especially rare ones) aren't yet handled. + if runtime.GOOS == "ios" { + // Memory is tight on iOS. Free what we can while we + // can before this potential burst of in-use memory. + debug.FreeOSMemory() + } + nm := ms.netmap() ms.lastNetmapSummary = nm.VeryConcise() ms.occasionallyPrintSummary(ms.lastNetmapSummary)