# Reference Cycle Between VM and VC Using Combine

**URL:** <https://forums.swift.org/t/reference-cycle-between-vm-and-vc-using-combine/59717>\
**Category:** Using Swift\
**Tags:** combine\
**Created:** [August 17, 2022, 2:18pm UTC](https://forums.swift.org/t/reference-cycle-between-vm-and-vc-using-combine/59717 "2022-08-17T14:18:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dennis\_U](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/dennis_u/32/16260_2.png) [@Dennis\_U](https://forums.swift.org/u/Dennis_U)\
**Post date:** [August 17, 2022, 2:18pm UTC](https://forums.swift.org/t/reference-cycle-between-vm-and-vc-using-combine/59717/1 "2022-08-17T14:18:02Z")

</div>

Memory leak. Could anybody explaining why?????? I'm new to Combine so any help is highly appreciated 😢  
Thank you in advance.

VM:

```swift

class ArchivedAppealsViewModelImp: ArchivedAppealsViewModel {
    var appeals = PassthroughSubject<[CurrentAppealsCellModel], Never>()
    private(set) var petitionRouter: PetitionRouter
    
    init(petitionRouter: PetitionRouter) {
        self.petitionRouter = petitionRouter
    }
    
    func loadCellModels() {
// do some networking here
        let fakeCellModels = (0...10).map { _ in CurrentAppealsCellModel(
            hasBeenRead: Bool.random(),
            description: "Some fake description",
            status: "Waiting for manager call",
            time: " 18:25",
            serialNum: "Num № 25-6541 от 22.03.2020")
        }
        
        appeals.send(fakeCellModels)
    }
    
    func executeActionForCell(at index: Int) {
        petitionRouter.routeToPetition()
        print("👇🏻 Cell at index: \(index) was tapped")
    }
}

```

Controller:

```swift

class ArchivedAppealsController: CustomPageViewController {
    private var viewModel: ArchivedAppealsViewModel
    private let contentView = ArchivedAppealsControllerView()
    private var disposedBag = Set<AnyCancellable>()
    
    override func loadView() {
        view = contentView
    }
    
    override func viewDidLoad() {
        bindVMToContentView()
        viewModel.loadCellModels()
        contentView.onCellAtIndexTapAction = { [unowned self] index in
            self.viewModel.executeActionForCell(at: index)
        }
    }
    
    init(viewModel: ArchivedAppealsViewModelImp,
         tapName: String) {
        self.viewModel = viewModel
        super.init(id: tapName)
    }
    
    private func bindVMToContentView() {
        viewModel.appeals
            .receive(on: RunLoop.main)
            .sink { [unowned self] in self.contentView.appeals = $0 }
            .store(in: &disposedBag)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

```
