I'm a new developer, and my app has a collection view (scrolling horizontally) with 32 images. I have created arrays for the images, labels, and text. As I get to the end of the list, the app crashes. Regardless of the size of my images, I am getting 'Message from debugger: Terminated due to memory issue'. I have utilized the Instruments tool, which seems to indicate the the images are not being released.
I tried to resize the images but with no successs. I also tried using autoreleasepool, which I may have used incorrectly.
My image array is set up like this with images 1-32.
let imageArray = [UIImage (named: "1"), UIImage (named: "2"), etc.]
Here is my collectionView:
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.imageArray.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MainCollectionViewCell", for: indexPath) as! MainCollectionViewCell
cell.imgImage.image = imageArray [indexPath.row]
cell.lblImageName.text = nameArray [indexPath.row]
return cell
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let mainStoryboard:UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let desVC = mainStoryboard.instantiateViewController(withIdentifier: "DetailViewController") as! DetailViewController
desVC.image = imageArray[indexPath.row]!
desVC.name = nameArray[indexPath.row]
desVC.text = textArray[indexPath.row]
self.navigationController?.pushViewController(desVC, animated: true)
}