工具:泄漏和分配(tvOS) [英] Instruments: Leaks and Allocations (tvOS)

查看:88
本文介绍了工具:泄漏和分配(tvOS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用tvOS应用.这是我的第一个本地(Swift)应用程序.该应用程序将是数字标牌应用程序,用于活动期间或公司办公室中. 与iOS/tvOS上的典型应用程序相比,一个很大的不同是它需要几乎全天候运行24/7,因此内存是此应用程序的一大主题.最小的泄漏最终将导致应用程序崩溃.

I’m currently working on a tvOS app. This is my first native (Swift) app. The app will be a digital signage app, used during events or in offices of companies. One big difference compared to a typical app on iOS/tvOS is that it needs to run pretty much 24/7, so memory is a big topic for this app. The smallest leak will eventually cause the app to crash.

该应用程序不断循环浏览一组全屏幻灯片.在屏幕的底部,有一个包含10篇文章的置顶栏中(每10秒钟刷新一次-现在在开发过程中).以下是天气幻灯片的屏幕截图,以了解您的想法.

The app is constantly looping through a set of fullscreen slides. At the bottom of the screen there is a ticker with 10 articles (refreshed every 10 seconds - now during development). Below is a screenshot of the weather slide, to get an idea.

当前一段时间后,该应用程序崩溃了,我很确定自己已将其范围缩小到股票行情栏(停用该功能后,该应用程序可以使用几天).如果我使用仪器中的泄漏"预设,则会得到以下结果:  看起来好像是泄漏了Article实例.我每10秒钟重新创建一次Article实例,并将其提供给置顶组件.我认为这就是为什么新实例每隔10秒就会泄漏一次.

Currently the app is crashing after a period of time and I’m pretty sure I’ve narrowed it down to the ticker component (when disabling it, the app lives for days). If I use the ‘Leaks’ preset in Instruments I get the following result:  It looks like it’s leaking Article instances. I’m recreating Article instances every 10 seconds and providing them to the ticker component. I think that is why new instances leak every ~10 seconds.

在我开始使用Instruments中的"Leaks"预设之前,我使用了"Allocations"预设,而对我来说,使用这些预设似乎还不错.但是我可能会误读结果了……

Before I started using the ‘Leaks’ preset in Instruments, I used the ‘Allocations’ preset, while using this all seemed fine to me. But I’m probably misreading the results…

使用分配:  我读这本书的方式是,目前内存中存在10个Article实例,并且已经存在31个实例,但现在已将它们清除-因此,我很安全.

Using allocations:  The way I read this is that currently 10 Article instances exist in memory, and 31 have existed but are cleaned up now - so I’m safe.

但是应用仍然崩溃.

我在保留周期方面读了很多书,在我认为应该的地方实施弱/无人管理.

I’ve read a lot on retain cycles, implemented weak/unowned where I believe I should.

所以我的问题不只是代码,而是更多有关如何读取此数据,泄漏"在此情况下的含义,以及为什么我为什么不将这些泄漏"视为分配中的持久对象? 窗口?

So my question is not so much about code, but more about how to read this data, what does a Leak mean in this context, and why do I see these ‘leaks’ not as persistent objects in the Allocations window?

(测试是在多台设备+模拟器上完成的)

(tests are done on multiple devices + simulator)

推荐答案

几周后我回来了,试图找出问题所在.好消息,我发现了泄漏,并解决了!

I’m back after weeks trying to figure out what was wrong. The good news, I found my leak, and solved it!

此问题已解决,方法是删除另一个闭包内的闭包,并在第一个闭包中保留对变量的引用.这导致了保留周期.

The issue was solved by removing a closure inside another closure keeping a reference to a variable in the first closure. This caused a retain cycle.

我真的不明白为什么我没早找到它,我在这里问了一个新问题:

I really don’t understand why I didn’t find it earlier, I asked a new question for this here: getting-different-data-in-instruments-based-on-method-of-profiling.

这篇关于工具:泄漏和分配(tvOS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆