Memory is not released during perform batch updates in CollectionView.

Memory is not released during perform batch updates in CollectionView.


I've been working on a project of using two

UICollectionView
's I have on that is the MainViewController with full screen cells that scroll horizontally and one that sits on that full screen cell and scrolls vertically. I have a functionality that adds as well as deletes cells. When a user taps and one of the pages of the MainViewController is deleted using the code below the memory that grew as cells were added is still being retained. Is there something Im doing wrong. All of my delegates are weak references and none of my cells have self referencing closures. Am I doing something wrong thank you for you help



Add or Remove Cell Delegate

func addCell(){ self.mainCollectionView.performBatchUpdates({ 
guard let last = arr.last else{ 
return } arr.append(last + 1) 
let lastIndex = IndexPath(item: last, section: 0) 
self.mainCollectionView.insertItems(at: [lastIndex]) 
}) { (completed) in 
print("Batch updates completed, performed successfully: \(completed)") 
} 
}  

func removeCell() { 
self.mainCollectionView.performBatchUpdates({ 
arr.popLast() 
self.mainCollectionView.deleteItems(at: [IndexPath(item: arr.count - 1, section: 0)])  
}) { (competed) in print("Perform batch updates completed") 
} 
}


Full Sized Cell Cell Population

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: FullPageCell.reuseIdentifier, for: indexPath) as? FullPageCell else{ 
assertionFailure("Fatal Error FullPageCell not dequed") 
return UICollectionViewCell() 
} 
cell.backgroundColor = UIColor.green 
cell.cellTappedDelegate = self  
return cell 
}  
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { 
if let cell = cell as? FullPageCell{ 
cell.setUpCollectionView() 
}
 }

SubCollectionView sitting on Full Page Cell Population

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: SmallCell.reuseIdentifier, for: indexPath) as? SmallCell else{ 
assertionFailure("Fatal Error FullPageCell not dequed") 
return UICollectionViewCell() 
} 
cell.backgroundColor = UIColor.yellow 
cell.imageView.image = self.image 
return cell 
}