173得票11回答
如何正确处理Swift块中带参数的Weak Self

在我的TextViewTableViewCell中,我有一个变量来跟踪一个块,并且有一个配置方法,在该方法中将该块传递并赋值。 这是我的TextViewTableViewCell类:// // TextViewTableViewCell.swift // import UIKit cla...

61得票2回答
在dispatch_async函数中使用weak self

我看了很多关于在dispatch_async里使用__weak self的帖子,现在有点困惑。如果我有:self.myQueue = dispatch_queue_create("com.biview.core_data", NULL); dispatch_async(self.myQueu...

59得票10回答
深入理解保留周期

假设我们有三个对象:祖父、父亲和孩子。祖父保留了父亲,父亲保留了孩子,孩子保留了父亲。祖父释放了父亲。 在这种情况下会发生什么?

58得票10回答
使用弱引用指向NSTimer目标以防止循环引用。

我正在像这样使用 NSTimer:timer = [NSTimer scheduledTimerWithTimeInterval:30.0f target:self selector:@selector(tick) userInfo:nil repeats:YES]; 当然了,NSTimer ...

54得票7回答
在UIView.animateWithDuration(...)的闭包中是否需要使用[unowned self]?

UIView.animateWithDuration(1, animations: { [unowned self] in self.box.center = self.boxTopRightPosition }, ...

42得票2回答
嵌套块内引用弱引用

假设我已经创建了一个弱引用对象,使用方式为__weak typeof(self) weakSelf = self; [self doABlockOperation:^{ ... }]; 在该块内,如果我嵌套另一个块:[weakSelf doAnotherBlockOperati...

40得票4回答
在从UIViewController调用的非保留完成块中引用self时,是否真的需要使用weakSelf/strongSelf技巧?

假设我有一个在UIViewController子类中的以下方法:- (void)makeAsyncNetworkCall { [self.networkService performAsyncNetworkCallWithCompletion:^{ dispatch_a...

29得票3回答
在ARC中,我们需要在UIAnimationBlocks中使用__weak self吗?

在UIAnimation块中,我们需要使用__weak self吗?如果我们没有将self声明为weak,它是否会创建内存泄漏的问题?[UIView animateWithDuration:animationDuration delay:0 ...

22得票3回答
递归块和ARC中的保留循环

编辑2: 不。建议的答案是关于异步调用。我想要并需要同步调用,就像普通的标准递归调用一样。 编辑: 当......__unsafe_unretained void (^unsafe_apply)(UIView *, NSInteger) ; 编译时没有警告或错误,但在运行时,将NULL存...

21得票2回答
在这个块中强引用 'self' 很可能会导致循环引用问题。

我有一个带有block的请求。但是编译器会发出警告: "在这个block中强引用了'self',很可能导致循环引用" __weak typeof(self) weakSelf = self; [generalInstaImage setImageWithURLRequest:[NSUR...