问题标签 [retain-cycle]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
77 浏览

ios - 在处理 Swift 对象和数组时,保留真的很重要吗?

出于这个问题的目的,假设我有一个代表任何给定类型数据的类。这些类的对象可以相互“连接”以形成一个网络。

据我了解,Swift 数组保留对象。在多个相互关联的DataObject实例的情况下,保留是否为性能下降/内存泄漏提供任何范围?这种特殊的问题模式被称为什么?

0 投票
2 回答
382 浏览

ios - 保留循环和仪器

我刚刚写了这个保留循环:

显然,Driver 和 Car 具有很强的属性。

无论如何,Instruments 没有在 Xcode 6.1 上的 Leaks -> Cycles & Roots 中显示保留周期。

这是一个保留周期,对吗?那是怎么回事?

0 投票
2 回答
130 浏览

objective-c - 如何在Cocos2d中使用ARC属性保存对子节点的引用

我有一个自定义CCNode类,它有一堆子节点,我想保留对子节点的引用以进行一些自定义转换。

例如对于子背景,自定义类如下所示:

问题是这会导致 ARC 上的保留周期,而节点背景永远不会从内存中释放出来。

0 投票
0 回答
68 浏览

cocos2d-iphone - How to properly keep a local reference to a child CCNode in a custom class in ARC

So, I want to hold a local reference to a child CCNode in a CCNode custom class without creating a retain cycle or without having the compiler complaining that the property or instance variable may be unpredictable set to nil

For instance with this custom class

...I have a retain cycle creating a node like this

where background and node are never freed from memory when the scene is replaced

Changing the property background to weak causes the compiler to complain in the lines with star (*) in the code above saying that the weak property or instance variable may be unpredictable set to nil

Update:

This is another approach with a weak instance variable and the settler and getter methods, the local strong variable (*) is because if the method uses the weak ivar _background the compiler complains saying that it may be unpredictable set to nil.

Is this approach a good thing to do in this case?

0 投票
2 回答
675 浏览

ios - 块中具有强引用的弱变量:不创建保留循环?

为什么当我们将弱引用传递给块内的强引用时它会起作用?如果块中的局部变量被保留,这应该添加一个保留self,从而创建这个糟糕的保留循环?

这是示例:

0 投票
1 回答
2714 浏览

ios - Swift 保留周期和闭包

我试图做很多关于理解保留周期的研究。不过,我似乎在我的例子中找不到任何东西。我确实知道,如果我将属性设置为闭包,则会发生保留周期并且需要使用弱或无主。但是我有 2 个示例,我想知道它们是否正确完成:提前致谢,我已经尝试查看它们是否已经在 stackoverflow 上,但找不到任何东西。

简单的动画

带有数组的动画

在这两个示例self中都是UIView. 我只想知道我做得正确,或者我是否也应该使用 imageView 作为弱参考。谢谢。

0 投票
6 回答
13728 浏览

ios - 是否有必要在 UIView.animateWithDuration(...) 的闭包中使用 [unowned self]?

是否有必要避免内存泄漏?

0 投票
1 回答
1887 浏览

objective-c - 强烈地在这个block里很可能会导致一个retain cycle

我使用活动指示器视图创建自定义单元格使用 SDWebImage 我在下载图像时隐藏了活动指示器

但是我执行了我看这个警告的代码

在此块中强烈捕获“customCell”可能会导致保留周期

谢谢

0 投票
1 回答
78 浏览

ios - 存储为变量的函数会导致引用循环吗?

如果我有一个类,将其他类函数存储为变量,那会导致引用循环吗?

例如

我不能在 ClassB 中将变量函数存储为弱或无主,那么这会导致引用循环吗?或者这只是反映了我对参考周期/功能的理解不足?

0 投票
4 回答
1850 浏览

ios - 如果从 Block 调用的方法使用 self,我是否需要使用弱 self 指针?

在块中使用self.会导致保留周期,因此我需要创建对weakSelf. 我明白这一点

但!

如果从我的块中调用一个使用self“的方法,这是否也会导致保留周期?例​​如,如果我UITableView从块中重新加载 a 并且在UITableView我调用的某些委托方法中self.,我是否会导致保留周期?这是否意味着我必须到处传递这个弱引用吗?看起来很做作。