How to Debug "Terminated Due to Memory Error"

Message from debugger: Terminated due to memory issue in device only

Yes, its possible that you may have silent complier about your warnings but it is possible that your app may over use memory i.e. memory is not optimised properly.

Message from debugger: Terminated due to memory issue.

Possibly there may be memory leaks or may be the memory overload (like view controller is remain in memory even after pop/dismiss due to strong reference to it.)

How to check:

  • You need to build app with profile (cmd + i) and select Allocation from the options and then test you app.

  • You will see the all the view controllers that is being allocates and deallocates during testing.

  • Just identify the view controllers that are taking too much memory and try to optimise its memory.

  • Also you can identify the view controller that remains in memory (not deallocates) even after pop/dismiss.

Ios Xcode Message from debugger: Terminated due to memory issue

What device is this happening on? Once your app is in the background you can expect for it to be killed at any time - it doesn't have to be using excessive memory.

If the new foreground app wants more memory, the OS will give it as much as it can. It will send a memory warning to any backgrounded apps. If they don't respond by reducing the memory footprint, or the foreground app still wants more memory, then the background apps are killed.

Your app isn't crashing, it is being killed by the OS because it is no longer the foreground app and its resources are needed elsewhere.

Message from debugger: Terminated due to memory issue in Xcode 10.1...image array?

Keep Image names in an Array and in the dataSource get image name from array and construct image.

let imageArray = ["1", "2"]

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MainCollectionViewCell", for: indexPath) as! MainCollectionViewCell

cell.imgImage.image = UIImage (named: imageArray [indexPath.row])
cell.lblImageName.text = nameArray [indexPath.row]

return cell
}

Note: If you still face memory issue then you might be loading heavy
resolution images, better resize them in background thread and assign
to imageView on main Thread.



Related Topics



Leave a reply



Submit