Im stuck with retain cycle caused by usage of UIHostingController.
In memory graph I can clearly see that there is retain cycle(image provided) and I dont know how to break it.
Also to mention MemberTraingDetailsComponent view property is added to Screen using screen.view.addSubview(memberTrainingDetailsComponent.view)
class MemberTrainingDetailsComponent: DefaultHostingController<DetailsSectionView<MemberDetailsSection>> {
required init(parent: ContainerComponent?) {
super.init(rootView: DetailsSectionView<MemberDetailsSection>(parentComponent: parent, viewModel: TrainingTagComponentViewModel(screen: parent as? Screen)))
}
@MainActor required dynamic init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
here is DefaultHostingController subclass
class DefaultHostingController<Content>: UIHostingController<Content>, HostingScreen where Content: View {
required init(parent: ContainerComponent?) {
fatalError("init(coder:) has not been implemented")
}
static var size: CGSize {
.zero
}
override init(rootView: Content) {
super.init(rootView: rootView)
}
[Memory graph screenshot showing retain cycle]
[Memory graph screenshot showing objects causing retain cycle]
I dont know why _view
and host
keeps strong refrences to each other. I also want to know where and when is rootView added inside HostingController view propperty..