Skip to content

Commit 26986a5

Browse files
authored
Fix memory leak in IntrospectionStore and dangling pointer in introspectionController (#512)
1 parent 30cf2a9 commit 26986a5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Sources/IntrospectionView.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ struct IntrospectionView<Target: PlatformEntity>: PlatformViewControllerRepresen
132132

133133
static func dismantlePlatformViewController(_ controller: IntrospectionPlatformViewController, coordinator: Coordinator) {
134134
controller.handler = nil
135+
IntrospectionStore.shared.removeValue(forKey: controller.id)
135136
}
136137
}
137138

@@ -211,11 +212,11 @@ extension PlatformView {
211212
fileprivate var introspectionController: IntrospectionPlatformViewController? {
212213
get {
213214
let key = unsafeBitCast(Selector(#function), to: UnsafeRawPointer.self)
214-
return objc_getAssociatedObject(self, key) as? IntrospectionPlatformViewController
215+
return (objc_getAssociatedObject(self, key) as? Weak<IntrospectionPlatformViewController>)?.wrappedValue
215216
}
216217
set {
217218
let key = unsafeBitCast(Selector(#function), to: UnsafeRawPointer.self)
218-
objc_setAssociatedObject(self, key, newValue, .OBJC_ASSOCIATION_ASSIGN)
219+
objc_setAssociatedObject(self, key, Weak(wrappedValue: newValue), .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
219220
}
220221
}
221222
}

0 commit comments

Comments
 (0)