Xcode 内存图是否为非内存周期的强引用提供任何智能视觉指示器? [英] Does Xcode Memory graph offer any smart visual indicators for strong references that aren't memory cycles?

查看:20
本文介绍了Xcode 内存图是否为非内存周期的强引用提供任何智能视觉指示器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为我之前的后续如何使用 dispatchQueues 创建引用循环?:

对于强引用(会造成泄漏,但不是引用循环)例如TimerDispatchSourceTimerDispatchWorkItem,内存图没有创建紫色图标,我怀疑是因为没有找到两个对象强烈地指着对方.

For the strong references (that create leaks, but aren't reference cycles) e.g. Timer, DispatchSourceTimer, DispatchWorkItem, the memory graph doesn't create a purple icon, I suspect it's simply because it doesn't find two objects pointing back to each other strongly.

我知道我可以来回观察一个特定的类没有离开内存,但想知道 Xcode 是否提供了更多的东西.

I know I can go back and forth and observe that a specific class is just not leaving the memory, but wondering if Xcode is providing anything more.

  • 还有其他指标吗?
  • 我知道 Xcode 可以直观地显示内存中类型的实例数.但是有没有办法过滤内存中超过 3 个实例的对象?

推荐答案

你问:

对于强引用(会造成泄漏,但不是引用循环)例如TimerDispatchSourceTimerDispatchWorkItem,内存图没有创建紫色图标,我怀疑是因为没有找到两个对象强烈地指向对方.

For the strong references (that create leaks, but aren't reference cycles) e.g. Timer, DispatchSourceTimer, DispatchWorkItem, the memory graph doesn't create a purple icon, I suspect it's simply because it doesn't find two objects pointing back to each other strongly.

是的.或者更准确地说,当有两个(或更多)对象之间只有强引用存在时,就会产生强引用循环警告.

Yes. Or more accurately, the strong reference cycle warning is produced when there are two (or more objects) whose only strong references are between each other.

但是对于重复定时器、通知中心观察者、GCD 来源等,严格来说这些都不是强引用循环.问题在于所有者(保持对我们应用程序对象的强引用的对象)只是一些在我们的应用程序运行时不会被释放的持久对象.当然,从我们的角度来看,我们的对象可能仍然是被遗弃的记忆",但这不是一个循环.

But in the case of repeating timers, notification center observers, GCD sources, etc., these are not, strictly speaking, strong reference cycles. The issue is that the owner (the object that is keeping a strong reference to our app’s object) is just some persistent object that won’t get released while our app is running. Sure, our object might still be "abandoned memory" from our perspective, but it’s not a cycle.

举例来说,考虑重复定时器,它保持对我们对象的强引用.主 runloop 保持对该计时器的强引用,并且在计时器失效之前不会释放它.从狭义上讲,没有强引用循环,因为我们的应用程序没有对 runloop 或计时器的强引用.但尽管如此,重复计时器仍会保持对我们对象的强引用(除非我们使用了 [weak self] 模式或您所拥有的).

By way of example, consider repeating timer that is keeping strong reference to our object. The main runloop is keeping strong reference to that timer and won’t release it until the timer is invalidated. There’s no strong reference cycle, in the narrow sense of the term, as our app doesn’t have strong reference back to the runloop or the timer. But nonetheless, the repeating timer will keep a strong reference to our object (unless we used [weak self] pattern or what have you).

如果调试内存图"知道这些众所周知的持久对象(例如主运行循环、默认通知中心、libDispatch 等),并且可能会引起我们对这些持久对象之一的那些情况的关注,那就太好了对象是对我们的一个对象的最后一个强引用.但事实并非如此,至少在这一点上是这样.

It would be lovely if the "Debug Memory Graph" knew about these well-known persistent objects (like main runloop, default notification center, libDispatch, etc.), and perhaps drew our attention to those cases where one of these persistent objects were the last remaining strong reference to one of our objects. But it doesn’t, at least at this point.

这就是为什么我们采用返回到我的大部分自定义对象应该已经被释放的点"然后使用'调试内存图'来识别没有释放的内容并查看哪些强引用被持久化的原因".当然,如果 Xcode 能够自动将我们的注意力吸引到这些上就好了,但事实并非如此.

This is why we employ the technique of "return to point that most of my custom objects should be have been deallocated" and then "use ‘debug memory graph’ to identify what wasn’t released and see what strong references are persisting". Sure, it would be nice if Xcode could draw our attention to these automatically, but it doesn’t.

但是如果我们的应用程序有一些静止状态,我们知道应该仍然存在的有限类型的对象,这个调试内存图"功能仍然非常有用,即使没有像强引用循环这样的指标警告.

But if our app has some quiescent state, where we know the limited types of objects that should still be around, this "debug memory graph" feature is still extremely useful, even in the absence of some indicator like the strong reference cycle warning.

我知道我可以来回观察一个特定的类没有离开内存,但想知道 Xcode 是否提供了更多的东西.

I know I can go back and forth and observe that a specific class is just not leaving the memory, but wondering if Xcode is providing anything more.

  • 还有其他指标吗?

不,我不知道.

  • 我知道 Xcode 可以直观地显示内存中类型的实例数.但是有没有办法过滤内存中超过 3 个实例的对象?

再说一次,不,我不知道.

Again, no, not that I know of.

这篇关于Xcode 内存图是否为非内存周期的强引用提供任何智能视觉指示器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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