While on a roll, I updated to CMP 1.6.10-beta01 an...
# compose-ios
t
While on a roll, I updated to CMP 1.6.10-beta01 and see what I think is a new message in the console:
Copy code
Warning: ViewControllerBasedLifecycleOwner - 'ViewControllerBasedLifecycleOwner' received 'Action.DISPOSE' while in 'State.Running'. Make sure that view controller containment API is used correctly. 'removeFromParent' must be called before 'dispose'
I think I am doing all the right magic. For each ComposeViewController I embed as a Child VC and when the parent viewWillDisappear is called I call my method:
Copy code
private func teardownView() {
        child.willMove(toParent: nil)
        child.view.snp.removeConstraints()
        child.view.removeFromSuperview()
        child.removeFromParent()
        child = nil
    }
But I still get the warning above. What might I be doing wrong? And perhaps there is an example somewhere? I do notice leaks and my app cannot be used more than an hour or so before it runs out. Thanks!
and an example of the setup, if that helps:
Copy code
private func setupView() {
        
        child = Views_iosKt.ServiceSearchComposeViewController(viewModel: viewModel, clickable: false) { [weak self] action, service in
            switch action {
            case "staff":
                self?.performStaffPicker()
                break
            default:
                break
            }
        }
        
        view.addSubview(child.view)
        addChild(child)
        child.didMove(toParent: self)
        
        child.view.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalTo(<http://view.safeAreaLayoutGuide.snp.top|view.safeAreaLayoutGuide.snp.top>)
            make.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
        }
        
//        child.view.backgroundColor = .red
    }
Okay, I partly got this working, I think. The issue is that if I detach the child view controller from the parent too soon, then the ComposeUIViewController will not get any of the unload events. So I do not release the child when I get the viewDidUnload, but let the lower level handle it. And if I get a viewWillAppear and I still have the child on hand, I then go through the remove dance. This let me get rid of the warning above, and it does appear memory is behaving a little better...