Is it possible to debug "Terminated due to memory error"?

IosObjective CMemory ManagementAutomatic Ref-Counting

Ios Problem Overview


In a certain (consistent) point when my app is running, I consistently get the xcode error message

> Terminated due to memory error.

I cannot find the code causing the error, but I can tell what code is near the error (using breakpoints).

The error is caused directly after returning a certain cell in my implemenation of the

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

UITableViewDataSource delegate method. I can confirm that it is returning a valid UITableViewCell, but I think that explaining and posting that entire method would be a waste of your time. However, I suspect it might be caused by a rapid, massive allocation of memory.

It definitely says Terminated due to memory error, not memory pressure.

I would like to know what is message really means. Also, is there any way to debug this message? No crash report is generated.

I am using ARC and iOS 7.

Ios Solutions


Solution 1 - Ios

I was getting this error and could not understand what was wrong.

After some searching I found out that i forgot to disable zombies.

To disable do the following:

Select edit scheme

Deselect

Solution 2 - Ios

I was faced the same issue.("Terminated due to Memory Error") I had tried the above all answers but nothing work for me. Then i debug my code and found a for loop is running for infinity time with allocating memory to a array with nil value every time.its use 300+MB so it give this error

Thanks.

Solution 3 - Ios

I had exactly same issue. I thought it caused my program had memory leak or using too much memory. I use instruments and used allocating profile and program works fine. Also I ran program by device long enough, and it also works fine.

I also using iPad 3rd Gen for debugging, it might be causing because of that slow of the device or bug, it it seems like just Xcode and running from Xcode problem. Not the problem of memory leak or allocation.

If you make sure with instruments and running app on device itself and work

Solution 4 - Ios

I was using Tesseract for OCR and when my target text got scanned, a GIF was supposed to play. When the GIF started to play, there was a memory spike, from 70-80MB to 450MB. The problem was that GIF was taking too much memory, the app would crash and Xcode would show that message. So I removed the concerned imageView from the superview of the ViewController.

imageView.removeFromSuperview

After this, the app would still spike to 450MB but then immediately release and come down to 40MB

Solution 5 - Ios

Restart device worked for me. “Terminated due to memory error” message stopped to appear.

Solution 6 - Ios

Edit the scheme, under Diagnostics you'll find several options to guard allocations. Refer to the documentation for details.

Question is: does it really say "terminated due to memory error" and not "pressure"? Check in instruments if your app is running low on memory, if the app does seem to run low on memory then that's what you should focus on regardless what the exact message is.

Solution 7 - Ios

I got this error because I was adding full size photos to a collectionView cell sized 40x40. Read the 2 comments under the question from @matt. I had to scale down the images before adding them to the cell.

Solution 8 - Ios

I had similar issue in Xcode 11.3 wherein camera was getting calling every-time we press on try again button. If these is done multiple times then crash happens.

This was fixed when we disabled Zombie objects. Below are steps:

  1. Tap on project name present in top left. This will show list of targets present in project.
  2. Tap on Edit scheme

Screenshot-1

  1. Select Run option -> Diagnostics -> Uncheck Zombie Objects.

Screenshot-2

Now, run your project. It should work fine.

Solution 9 - Ios

With Xcode 11 it started my project in Debug mode. I am doing some image recording/editing/returning to the user and that is not something you can use in Debug. Once I turned to Release mode, all went well.

Solution 10 - Ios

I've faced this kind of issue due to inattentiveness.

I've been calling a function, which adds imageView as subview in:

override func layoutSubviews() {
    super.layoutSubviews()
}

This caused a huge memory usage, so be attentive to this sort of things!

Solution 11 - Ios

The thing that I noticed is that when I run my app on the device through cable and leave it idle for a long time I will also get that error.

Apple do address this and it just might be that it feels like the app is idle and just kills it.

Solution 12 - Ios

In my case it was a corrupted Image from the API which raised my memory from 100MB to 4.5 GB due to processing size it took to display on screen!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndrewView Question on Stackoverflow
Solution 1 - IoszirinispView Answer on Stackoverflow
Solution 2 - Iosmaanvender singhView Answer on Stackoverflow
Solution 3 - IosTomohisa TakaokaView Answer on Stackoverflow
Solution 4 - IosYash TamakuwalaView Answer on Stackoverflow
Solution 5 - IosOfir MalachiView Answer on Stackoverflow
Solution 6 - IosLearnCocos2DView Answer on Stackoverflow
Solution 7 - IosLance SamariaView Answer on Stackoverflow
Solution 8 - IosJayprakash DubeyView Answer on Stackoverflow
Solution 9 - Iosimpression7vxView Answer on Stackoverflow
Solution 10 - IosEmma VahradyanView Answer on Stackoverflow
Solution 11 - IosCyrus ZeiView Answer on Stackoverflow
Solution 12 - IosMarwan. KAView Answer on Stackoverflow