ehdrhelr / baseball

그룹프로젝트 #3
0 stars 1 forks source link

[iOS] Memory Leak? #29

Closed eeeesong closed 3 years ago

eeeesong commented 3 years ago

self가 가지고 있는 요소의 delegate를 self로 지정해서 강한 참조가 발생한 게 아닐까요..? tableView의 dataSource나 delegate가 weak 으로 되어있으니 viewModel의 delegate도 weak하게 설정해주면 되는 것 같기도 하네요!!

    private func configureDataSource() {
        self.dataSource = UITableViewDiffableDataSource.init(tableView: self.gameListTableView) { (tableView, indexPath, game) -> UITableViewCell in

            let cell = self.gameListTableView.dequeueReusableCell(withIdentifier: GameCell.reuseIdentifier) as! GameCell

            self.viewModel.setCellInfo(with: game)
            self.viewModel.delegate = self // <- ? 

            cell.updateUI(with: self.viewModel)
            self.bindSelection(with: cell)

            return cell
        }
    }

다만 메모리 그래프가 여전히 안 열려서 확인은 전혀 못해봤어요 OS 업데이트 문젠가 싶어서 업데이트 데이터 다운로드 중입니다ㅎㅎ..

eeeesong commented 3 years ago
    private func configureDataSource() {
        self.dataSource = UITableViewDiffableDataSource.init(tableView: self.gameListTableView) {
            [weak self] (tableView, indexPath, game) -> UITableViewCell in

            guard let self = self else { return UITableViewCell() }

            let cell = self.gameListTableView.dequeueReusableCell(withIdentifier: GameCell.reuseIdentifier) as! GameCell

            self.viewModel.setCellInfo(with: game)
            self.viewModel.delegate = self

            cell.updateUI(with: self.viewModel)
            self.bindSelection(with: cell)

            return cell
        }
    }
eeeesong commented 3 years ago
class SelectViewModel {
    weak var delegate: GameCellDelegate!
}
protocol GameCellDelegate: AnyObject {
    func didPressButton(with gameInfo: GameInfo)
}
Lia316 commented 3 years ago

수정 완료!

Lia316 commented 3 years ago

weak delegate protocol 관련 참고 블로그 memory leak 원인 관련 참고 블로그