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

查看:97
本文介绍了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.

通过示例,考虑重复计时器,该计时器对我们的对象保持强烈的参考.主运行循环会牢牢引用该计时器,并且在计时器无效之前不会释放它.从狭义上讲,没有强大的参考周期,因为我们的应用没有对运行循环或计时器的强大参考.但是,尽管如此,重复计时器将对我们的对象保持强烈的引用(除非我们使用了[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).

如果"Debug Memory Graph"了解这些众所周知的持久性对象(例如主运行循环,默认通知中心,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个以上实例的对象?
  • I know Xcode visually shows the number of instances of a type in memory. But is there a way to filter objects that have more than 3 instances in memory?

再次,不,不是我所知道的.

Again, no, not that I know of.

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

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