In D_Gen3.memgraph, Xcode memory debugger reports one leaked type, the Color
for the bullseye in an HSV color picker, which adapts to brightness. Instruments would report thousands of leaks, 99% not referring to app code.
% leaks D_Gen3.memgraph
9 com.apple.SwiftUI 0x1c94e6318 partial apply for closure #1 in ViewBodyAccessor.updateBody(of:changed:) + 44
8 Inclusivity 0x102dc53e8 protocol witness for View.body.getter in conformance HSVHueSatWheelBullseye + 40 <compiler-generated>:0
7 Inclusivity 0x102dc3594 HSVHueSatWheelBullseye.body.getter + 820 HSVHueSatWheelBullseye.swift:12
6 com.apple.SwiftUI 0x1c9e748ac ZStack.init(alignment:content:) + 180
5 Inclusivity 0x102dc409c closure #1 in HSVHueSatWheelBullseye.body.getter + 960 HSVHueSatWheelBullseye.swift:20
4 Inclusivity 0x10317f9ec HSVColorPickerVM.targetRingColor.getter + 292 HSVColorPickerVM.swift:198
3 com.apple.SwiftUI 0x1c98e888c Color.init(hue:saturation:brightness:opacity:) + 80
2 libswiftCore.dylib 0x1b1e2c9b4 swift_allocObject + 64
1 libswiftCore.dylib 0x1b1e2c7bc swift_slowAlloc + 64
0 libsystem_malloc.dylib 0x1a4377bc8 _malloc_zone_malloc + 160
1 (48 bytes) ROOT LEAK: <SwiftUI.(ColorBox in $1c9f228c0)<SwiftUI.Color.Resolved> 0x12bb86c80> [48]
This is the getter for that Color in an ObservableObject
, whose lifetime and count is exactly as expected.
var targetRingColor: Color {
currentSharedColor.val > 0.55
? Color(hue: 0,
saturation: 0,
brightness: min(0.2, 1 - Double(currentSharedColor.val))) // currentSharedColor is a private value type
: Color(hue: 0,
saturation: 0,
brightness: max(0.8, 1 - Double(currentSharedColor.val)))
}
and here it is in a View
Circle().fill(vm.targetRingColor)
.frame(width: vm.hsBullseyeDiameter, height: vm.hsBullseyeDiameter)
.transition(AnyTransition.scale.animation(.easeInOut))
.animate(.easeIn, value: vm.hideBullseye)
.animate(.easeIn, value: vm.hsBullseyeDiameter)
The .animate modifier is just sugar for respecting ReduceMotion. (PS. Please add a zero-effort way to low key or cut off motion by an API like this!)