Is it possible to debug “Terminated due to memory error”?

前端 未结 11 1616
Happy的楠姐
Happy的楠姐 2020-11-29 05:57

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

Terminated due to memory error.

相关标签:
11条回答
  • 2020-11-29 06:18

    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

    0 讨论(0)
  • 2020-11-29 06:24

    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

    0 讨论(0)
  • 2020-11-29 06:24

    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.

    0 讨论(0)
  • 2020-11-29 06:25

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

    0 讨论(0)
  • 2020-11-29 06:27

    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!

    0 讨论(0)
提交回复
热议问题