Skip to content

Fix memory leak in #161 and regression in #194 #192

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Introspect/UIKitIntrospectionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,18 @@ public struct UIKitIntrospectionView<TargetViewType: UIView>: UIViewRepresentabl
return view
}

/// In some cases, UIView does not call `moveToWindowHandler`,
/// so the `moveToWindowHandler` call in updateUIView must be preserved.
public func updateUIView(
_ uiView: IntrospectionUIView,
context: UIViewRepresentableContext<UIKitIntrospectionView>
) {}
) {
uiView.moveToWindowHandler?()
}

/// Avoid memory leaks.
public static func dismantleUIView(_ uiView: IntrospectionUIView, coordinator: ()) {
uiView.moveToWindowHandler = nil
}
}
#endif
13 changes: 11 additions & 2 deletions Introspect/UIKitIntrospectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,18 @@ public struct UIKitIntrospectionViewController<TargetViewControllerType: UIViewC
return viewController
}

/// If you find that the `moveToWindowHandler` is not called in certain situations (which has not been discovered yet),
/// you can add code to call the `moveToWindowHandler` in the function body.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has come to pass as reported in #194 so I'll be taking over and including the fix here.

public func updateUIViewController(
_ uiViewController: IntrospectionUIViewController,
_ viewController: IntrospectionUIViewController,
context: UIViewControllerRepresentableContext<UIKitIntrospectionViewController>
) {}
) {
(viewController.view as? IntrospectionUIView)?.moveToWindowHandler?()
}

/// Avoid memory leaks.
public static func dismantleUIViewController(_ viewController: IntrospectionUIViewController, coordinator: ()) {
(viewController.view as? IntrospectionUIView)?.moveToWindowHandler = nil
}
}
#endif