Guys I'm trying to fix memory leak through Debug Memory Graph and struct here.
My code in UICollectionView, cellForItemAt indexPath
is as follow
guard let cell = collectionView?.dequeueReusableCell(withReuseIdentifier: cellIdentifier, for: indexPath) as? DiscoveryCell else {
Log.error("DiscoveryCell not registered")
return UICollectionViewCell()
}
let buttonView = self.delegate?.getBottomView(template: viewModel)
cell.configure(model: viewModel, buttonView: buttonView)
return cell
and custom cell contains
class DiscoveryCell: UICollectionViewCell, Identifiable {
private(set) var viewModel: DiscoveryProtocol?
@IBOutlet private var buttonContainerView: UIView!
func configure(model: DiscoveryProtocol, buttonView: UIView?) {
guard let viewModel = model as? DiscoveryProtocol else {
return
}
self.viewModel = viewModel
if let actionButtonView = buttonView {
actionButtonView.frame = buttonContainerView.bounds
self.buttonContainerView.addSubview(actionButtonView)
}
}
override func prepareForReuse() {
super.prepareForReuse()
self.buttonContainerView.subviews.forEach { subview in
subview.removeFromSuperview()
}
}
}
what's wrong with my code? I mean where do I find the memory leaks