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

95,479

Solution 1

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

Solution 2

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

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

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

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

Share:
95,479

Related videos on Youtube

Andrew
Author by

Andrew

Updated on July 05, 2022

Comments

  • Andrew
    Andrew almost 2 years

    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.

    • user963601
      user963601 over 10 years
      I saw the same error in Xcode. My app was crashing because I was creating a super-tall UIWebView (greater than 20000 pixels). I was never able to find a crash report, nor figure out a way to get memory warnings before the crash.
    • Andrew
      Andrew over 10 years
      @HeathBorders I am using a UIWebview as well. That is very interesting. I will have to check the height on mine. Thanks!
    • Pochi
      Pochi over 10 years
      This is kind of a common error with these components. The possible causes are: somehow you are generating too many cells (check your calculations), your cell sizes are wrong (as in dividing by 0 generating a nan which is kind of an infinite number when making the size). or incurring on an infinite loop.
    • Andrew
      Andrew over 10 years
      @HeathBorders Now I am interested to know what device you were testing on?
    • user963601
      user963601 over 10 years
      I was testing on an iPad3. Also, my UIWebView wasn't just super-tall, it was also super-wide (30000px).
    • Andrew
      Andrew over 10 years
      @HeathBorders This is very interesting. Everyone that participated in this post has been testing on iPad 3rd gen. Coincidence? Has anyone been able to reproduce the error on another device? I will try if I get a chance.
    • Andrew
      Andrew over 10 years
    • Andrew
      Andrew over 10 years
    • JgdGuy
      JgdGuy over 9 years
      I am running with the same problem :|
    • user1960169
      user1960169 over 8 years
      same problem with iphone 6 + for MKMapView. how can I solve it? it works fine in 4s
    • Dude
      Dude over 8 years
      same error iPhone 6+
    • Ramakrishna
      Ramakrishna about 8 years
      Same error in iPhone 6
  • Andrew
    Andrew over 10 years
    It definitely says "error" not "pressure". The memory level is consistently at about 15 MB at the time of crash.
  • LearnCocos2D
    LearnCocos2D over 10 years
    Then try with malloc diagnostics enabled. Btw are you testing on a device?
  • Andrew
    Andrew over 10 years
    Hmmm. Everyone that participated in this post has been testing on iPad 3rd gen. Coincidence?
  • Tomohisa Takaoka
    Tomohisa Takaoka over 10 years
    I only use iPad 3rd gen so I am not sure yet. Today I have ordered iPad mini retina, so I can provably answer this next week ;)
  • Peter
    Peter over 10 years
    Just encountered this on an iPhone5S. Just added Google's tracking code and had to reduce from arm64 to arm7/7s as Google's slooooww at building arm64. I'd assumed this was an arm64/7s thing. Certainly not just an iPad 3rd gen issue. I had 'error in __connection_block_invoke_2' which separate searches tells me might be related to downloading too much and OOMing. Shame about the lack of stacktrace though....
  • Slipp D. Thompson
    Slipp D. Thompson almost 10 years
    I'm encountering it on an iPad mini 2nd-gen (iPad4,4).
  • Neru
    Neru over 9 years
    I have similar issue when downloading whole bunch of images using NSURLSession. Simulator and standalone device(iPhone 6) works fine. In instruments, allocation diagram also looks smooth. Don't crash either. Problem occurs when I have device connected to xCode. No matter build configuration (Debug or Release). Always ends with mystery "Memory error".
  • zirinisp
    zirinisp almost 9 years
    When zombies are enable everything is affected as objects are not deallocated. This fills up the memory very fast in the case of a table view where a lot of thing are being allocated and deallocated. Definition of Enable Zombies: Replace deallocated objects with a “zombie” object that traps any attempt to use it. When you send a message to a zombie object, the runtime logs an error and crashes. You can look at the backtrace to see the chain of calls that triggered the zombie detector.
  • Ramakrishna
    Ramakrishna about 8 years
    I'm encountering it in iPhone6. Working fine on simulator but when i run my app in iPhone6 shows the memory error and also working fine in other devices like 5, 5S etc..
  • Saikiran Komirishetty
    Saikiran Komirishetty about 7 years
    U saved my time. Thank you.
  • I'm a Learner
    I'm a Learner about 7 years
    Still, I'm facing the problem. Please guide me.
  • I'm a Learner
    I'm a Learner about 7 years
    In my Universal app, I'm getting his problem with iPhone device 5s,6. But the same is working fine with iPad. So please suggest me for the same.
  • Sam
    Sam about 5 years
    How do you disable zombies?
  • Aleesha
    Aleesha over 4 years
    I spent 2 days to fix my memory crash, your solution helped. Thanks..!
  • Darrow Hartman
    Darrow Hartman about 3 years
    Yes! Thank you. I made a similar mistake, added splash images that were big. Make sure you make assets the correct size.
  • catcon
    catcon over 2 years
    This works for me. It's strange that the crash just appear out of the blue