RACCommunity / Rex

ReactiveCocoa Extensions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rex_text extensions seems to leave behind persistent objects

avalanched opened this issue · comments

commented

Setup: I have a UICollectionView with 4 UICollectionViewCell's that contain a UILabel

class SectionBarCollectionViewCell: UICollectionViewCell, ReactiveView {

    static let DefaultIdentifier = "identifier"
    var viewModel = MutableProperty<SectionBarCellViewModel?>(nil)
    let titleLabel = Label()

    override init(frame: CGRect) {
        super.init(frame: frame)
        commonInit()
    }

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        commonInit()
    }

    func commonInit() {
        contentView.addSubview(titleLabel)
        bindObservers()
    }

    func bindObservers() {

        titleLabel.rex_text <~ viewModel.producer |> flatMap(.Latest) { $0?.title.producer ?? SignalProducer(value: "") } |> ignoreNil
    }

    func bindViewModel(viewModel: AnyObject) {
        if let viewModel = viewModel as? SectionBarCellViewModel {

            self.viewModel.put(viewModel)
        }
    }
}

when I profile my application it seems that the UILabel won't get destroyed when the UICollectionViewCell's are deinit
screen shot 2015-08-20 at 15 30 30

if i do it without binding, it destroys the UILabel as suspected when the Cell is deinit.

viewModel.producer |> flatMap(.Latest) { $0?.title.producer ?? SignalProducer(value: "") } |> start(next: {[unowned self] title in self.titleLabel.text = title })

Took a quick look at the code and think I found the retain cycle. I'll have to spend some time testing it out and looking for a fix

commented

@neilpa Based on your fix, I have fixed all remaining retain cycles on UIKit extensions in #29