美文网首页
RAC订阅者释放机制

RAC订阅者释放机制

作者: 我是小胡胡分胡 | 来源:发表于2018-07-05 15:54 被阅读27次

    释放顺序如下

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

    but!

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

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

    -[RACCompoundDisposable dealloc]
    -[AFHTTPSessionManager dealloc]

    测试代码如下:

      RACSignal *signal =   [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _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订阅者释放机制

          本文链接:https://www.haomeiwen.com/subject/vbupuftx.html