简体   繁体   English

弱指针为零

[英]Weak Pointer is nil in block

I am creating a weakself just right above my block 我正要在自己的方块上方创建一个弱者

 __weak typeof (self) weakSelf = self;
    [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageNotAllowed timeoutInterval:10.0]
                                       queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError ){
                                           NSArray *array = weakSelf.myArray;
                                           NSError *error;

} }

In side the block the weakself is nil and every property related to weakself is also nil. 在块的一边,弱者为零,与弱者相关的每个属性也为零。

Can some tell me what i am doing wrong here? 有人可以告诉我我在做什么错吗?

There is nothing 'wrong' as such. 没有什么“错”。 The object pointed to by self has been deallocated (and thus the reference is nil ). self指向的对象已被释放(因此,引用为nil )。

Remember that the proximity of 2 pieces of code does not equate to the proximity of the time at which they will run when you are using asynchronous callbacks. 请记住,两段代码的接近度并不等于使用异步回调时它们将运行的时间。

You need to check why the instance is being deallocated when you don't expect it to be (you could implement dealloc and add a breakpoint there). 您需要检查一下为什么不希望实例被释放时为什么要释放实例(可以实现dealloc并在其中添加断点)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM