Code snippet:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: BroadCastFeedTableViewCell = broadCastTableView.dequeueReusableCell(withIdentifier: "broadCastFeedCell") as BroadCastFeedTableViewCell
cell.singlePicImageView.kf.setImage(with: URL(string: (self.broadCastArray[indexPath.row].images_url?[0])!), placeholder: nil, options: nil, progressBlock: nil)
{ (theImage, error, cache, url) in
if theImage != nil{
let imageHeight = self.getAspectRatioOfDownloadedImages(resolution: self.broadCastArray[indexPath.row].image_resolution![0])
cell.collectionContentViewHeightConstraint.constant = imageHeight
cell.layoutSubviews()
cell.layoutIfNeeded()
}else {
let placeHolderCenterCordi = UIView().getViewRelationWithSuperSuperView(viewControllerView: cell.collectionContentView,
subView: cell.singlePicImageView, subObjFrame: cell.singlePicImageView.frame)
cell.singlePicImageView.addPlaceHolderImageView(cordinates: placeHolderCenterCordi.center)
}
self.broadCastTableView.rowHeight = UITableViewAutomaticDimension
}
}
In above code I have used Kingfisher library to load image from remote server, whenever following code load certain images(GIF, JPEG, PNG) which may have large size (2-5 MB approx.) the app terminates due to memory issue. In iPhone 5s it terminates instantly as soon as app is launched and in other iPhone Model (7, 6s) it terminates after scrolling for certain amount of time. I have also check Allocation and leak but I didn't understand/found much about the issue.
I have also attached the profiling graph. This shows there is no such memory leaks, but due to some issue app is terminating:
I had a lot of problems with memory loading images. I cannot be certain of your case, but I can give you some helpful tips.
cell.layoutSubviews()
and then cell.layoutIfNeeded()
. The first one is force calling layoutSubviews, the second one is checking to see if there are stuff that needs to be laid out before calling layoutSubView. If you want to mark a view to be laid out you can do setNeedsLayout(). that will make the view layout updates on the next cycle.