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

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.

97633 次浏览

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.

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

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 "Enable Zombie Objects

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.

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

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

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.

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!

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.

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.

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.

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!

An infinite loop was the cause of the memory leak for me. I could see the memory in Xcode rising to 1,6 Gb at which point the app crashed. The app's memory usage should be in mb and not gb and it should be relativly stable. If it rises quickly, say 100 mb a second, there's definitely something wrong. If none of the suggestions above have worked, you should 1. check the memory usage of the app, and 2. if the usage is too high, look for loops you've recently added.