ios 是否可以调试“因内存错误而终止”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19203790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:06:49  来源:igfitidea点击:

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

iosobjective-cmemory-managementautomatic-ref-counting

提问by Santa Claus

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

在我的应用程序运行时的某个(一致)点,我始终收到 xcode 错误消息

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

UITableViewDataSourcedelegate 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.

UITableViewDataSource委托方法。我可以确认它正在返回一个有效的UITableViewCell,但我认为解释和发布整个方法会浪费你的时间。但是,我怀疑这可能是由快速、大量分配内存引起的。

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

它肯定说Terminated due to memory error,不是内存压力。

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 ARCand iOS 7.

我正在使用ARC和 iOS 7。

回答by zirinisp

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

取消选择“启用僵尸对象

回答by maanvender singh

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

我遇到了同样的问题。(“由于内存错误而终止”)我已经尝试了上述所有答案,但对我来说没有任何效果。然后我调试我的代码,发现 for 循环正在运行无限时间,每次都将内存分配给一个值为 nil 的数组。它使用 300+MB 所以它给出了这个错误

Thanks.

谢谢。

回答by Tomohisa Takaoka

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.

我也使用 iPad 3rd Gen 进行调试,这可能是由于设备或错误的缓慢造成的,它似乎只是 Xcode 并且从 Xcode 问题运行。不是内存泄漏或分配的问题。

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

如果您确保使用仪器并在设备本身上运行应用程序并正常工作

回答by Yash Tamakuwala

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.

我使用 Tesseract 进行 OCR,当我的目标文本被扫描时,应该播放 GIF。当 GIF 开始播放时,内存出现峰值,从 70-80MB 增加到 450MB。问题是 GIF 占用了太多内存,应用程序会崩溃并且 Xcode 会显示该消息。所以我从 ViewController 的 superview 中删除了相关的 imageView。

imageView.removeFromSuperview

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

在此之后,该应用程序仍会飙升至 450MB,但随后会立即释放并降至 40MB

回答by Ofir Malachi

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

重启设备对我有用。“由于内存错误而终止”消息停止出现。

回答by LearnCocos2D

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.

问题是:它真的说“由于内存错误而终止”而不是“压力”吗?如果您的应用程序内存不足,请检查仪器,如果应用程序似乎内存不足,那么无论确切消息是什么,您都应该关注它。

回答by impression7vx

With Xcode 11 it started my project in Debugmode. 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 Releasemode, all went well.

使用 Xcode 11,它以Debug模式启动我的项目。我正在做一些图像记录/编辑/返回给用户,这不是您可以在Debug. 一旦我转向Release模式,一切顺利。

回答by Emma Vahradyan

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

由于疏忽,我遇到了这种问题。

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

我一直在调用一个函数,该函数将 imageView 添加为子视图:

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

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

这导致了巨大的内存使用,所以要注意这种事情!

回答by Jayprakash Dubey

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

我在Xcode 11.3 中遇到了类似的问题,其中每次我们按下重试按钮时相机都会被调用。如果多次执行这些操作,则会发生崩溃。

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

当我们禁用 Zombie 对象时,此问题已得到修复。以下是步骤:

  1. Tap on project name present in top left. This will show list of targets present in project.
  2. Tap on Edit scheme
  1. 点击左上角的项目名称。这将显示项目中存在的目标列表。
  2. 点击编辑方案

Screenshot-1

截图 1

  1. Select Run option -> Diagnostics -> Uncheck Zombie Objects.
  1. 选择运行选项 -> 诊断 -> 取消选中僵尸对象。

Screenshot-2

截图 2

Now, run your project. It should work fine.

现在,运行您的项目。它应该可以正常工作。