xcode iOS内存使用量增加,找不到罪魁祸首

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28321954/
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-09-15 06:35:57  来源:igfitidea点击:

iOS memory usage increasing, can't find the culprit

iosxcodeafnetworkinginstruments

提问by Nathan Gaskin

I'm attempting to download a large number of images using AFNetworking 2.5 and stream them to disk. According to the memory monitor in Xcode, this is causing unbounded memory growth (and eventually memory warnings and force quits) - but profiling the memory usage using the allocations instrument shows the memory usage to be stable.

我正在尝试使用 AFNetworking 2.5 下载大量图像并将它们流式传输到磁盘。根据 Xcode 中的内存监视器,这会导致内存无限增长(并最终出现内存警告和强制退出) - 但使用分配工具分析内存使用情况表明内存使用情况稳定。

I'd like to think Xcode is just wrong here, but then why would my app be getting killed by iOS?

我想 Xcode 在这里是错误的,但是为什么我的应用程序会被 iOS 杀死?

Instruments shows this - the peaks are Core Data queries, then the rest is the images downloading - peaks at about 9.5MB, the rest sits at about 8.5MB

Instruments 显示了这一点 - 峰值是核心数据查询,然后是图像下载 - 峰值约为 9.5MB,其余约为 8.5MB

Instruments

仪器

I've also tried Heapshot Analysis - which shows a tiny bit of growth but nowhere near the amount reported by Xcode

我也尝试过 Heapshot Analysis - 它显示出一点点增长,但远不及 Xcode 报告的数量

Heapshot Analysis

堆快照分析

Xcode's memory monitor shows this - growing by multiple MB per iteration.

Xcode 的内存监视器显示了这一点 - 每次迭代增长数 MB。

Xcode Memory Usage

Xcode 内存使用

Is there any way to get Instruments to show me whatever Xcode is seeing? Or is there a better instrument to use to find out where all this memory is going?

有什么方法可以让仪器向我展示 Xcode 看到的任何内容?或者有没有更好的工具可以用来找出所有这些记忆的去向?

Thanks!

谢谢!

回答by matt

According to the memory monitor in Xcode, this is causing unbounded memory growth (and eventually memory warnings and force quits) - but profiling the memory usage using the allocations instrument shows the memory usage to be stable.

根据 Xcode 中的内存监视器,这会导致内存无限增长(并最终出现内存警告和强制退出) - 但使用分配工具分析内存使用情况表明内存使用情况稳定。

Believe Instruments and the Allocations information - notthe memory monitor in Xcode. The memory monitor graph is completely irrelevant. Ignore it.

相信仪器和分配信息 -而不是Xcode 中的内存监视器。内存监视器图完全无关。忽略它。

This is not because the memory monitor in Xcode is useless or wrong. It is because memory managementis completely different for a debug build than for a release build (Instruments uses a release build). This is especially true in Swift (you don't say whether you're using Swift).

这并不是因为 Xcode 中的内存监视器没有用或错误。这是因为调试版本的内存管理与发布版本的内存管理完全不同(Instruments 使用发布版本)。这在 Swift 中尤其如此(你没有说你是否在使用 Swift)。

Observe memory usage onlyon the device and onlyin a release build. Otherwise, you'll be completely misled.

在设备上且在发布版本中观察内存使用情况。否则,您将完全被误导。