2

I have a table view cell with a collection view. both bonded through rxdatasource, I am getting the leak using instruments when the view is loaded. Any thoughts on what could be the reason for this? Thanks.

the leak

image

HomeViewcontroller

 let dataSource = RxTableViewSectionedReloadDataSource<HomeSection>(configureCell:  { [weak self] dataSource, tableView, indexPath, item in
            guard let self = self else { return UITableViewCell() }

            switch item {
       ....
            case .homeTrendingItem(let viewModel):
                let cell = (tableView.dequeueReusableCell(withIdentifier: trendingIdentifier, for: indexPath) as? ModelProductsCell)!
                cell.delegate = self
                cell.bind(to: viewModel)
                return cell

            }
        }, titleForHeaderInSection: { dataSource, index in
            let section = dataSource[index]
            return section.title
        })

        output.items
            .bind(to: tableView.rx.items(dataSource: dataSource))
            .disposed(by: rx.disposeBag)

ModelProductsCell


func bind(to viewModel: ModelProductsViewModel) {
       let input = ModelProductsViewModel.Input()
       let output = viewModel.transform(input: input)

       output.items
       .bind(to: collectionView.rx.items(cellIdentifier: mainReuseIdentifier, cellType: ProductItemCell.self)) { collectionView, viewModel, cell in
               cell.bind(to: viewModel)
       }.disposed(by: cellDisposeBag)

       collectionView.rx.modelSelected(ProductCellViewModel.self)
           .bind {[weak self] vm in
               self?.delegate?.didTapOnItem(p: vm.product)
       }.disposed(by: cellDisposeBag)

       viewModel.loading.asObservable().bind(to: isLoading).disposed(by: rx.disposeBag)

       viewModel.loading.asDriver().drive(onNext: { [weak self] (isLoading) in
           isLoading ? self?.activityIndicator.startAnimating() : self?.activityIndicator.stopAnimating()
       }).disposed(by: cellDisposeBag)
   }

Mohamed ALOUANE
  • 5,349
  • 6
  • 29
  • 60
  • Is `ModelProductsCell.delegate` weak? It would help if you gave us a minimum _compilable_ sample exhibiting your problem. We are having to make way too many assumptions to help you. – Daniel T. May 21 '20 at 16:11
  • yes the delegate is weak. I created a new project with almost same approach and pods.but couldn't reproduce the leak! https://github.com/alouanemed/leakTest – Mohamed ALOUANE May 22 '20 at 20:52

0 Answers0