RAC订阅者释放机制

释放顺序如下

订阅后,信号立即就释放了
-[RACDynamicSignal dealloc]
-[RACSignal(Testing) dealloc]

but!

////为什么偏要等block调用完,才会释放

-[RACPassthroughSubscriber dealloc]
-[RACCompoundDisposable dealloc]
-[RACSubscriber dealloc]

-[RACCompoundDisposable dealloc]
-[AFHTTPSessionManager dealloc]

测试代码如下:

  RACSignal *signal =   [RACSignal createSignal:^RACDisposable * _Nullable(id  _Nonnull subscriber) {
        AFHTTPSessionManager*manaager=  [AFHTTPSessionManager manager];
        [manaager POST:@"https://www.baidu.com" parameters:nil progress:^(NSProgress * _Nonnull uploadProgress) {
            
        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            sleep(10);
            //[subscriber sendNext:@"111"];
           // [subscriber sendCompleted];
            [manaager invalidateSessionCancelingTasks:YES];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            sleep(10);
           // [subscriber sendError:nil];
            [manaager invalidateSessionCancelingTasks:YES];
        }];
        return  nil;
    }];
    
    
    [signal subscribeNext:^(id  _Nullable x) {
        DDLogVerbose(@"   %s ",__func__);
    } error:^(NSError * _Nullable error) {
        DDLogVerbose(@"   %s ",__func__);
    } completed:^{
        DDLogVerbose(@"   %s ",__func__);
    }];

你可能感兴趣的:(RAC订阅者释放机制)