What are the reference ownership semantics of ReactiveCocoa?

前端 未结 2 1495
温柔的废话
温柔的废话 2021-01-30 03:12

When I create a signal and bring it into the scope of a function, its effective retain count is 0 per Cocoa conventions:

RACSignal *signal = [self createSignal];         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 03:53

    I am trying to solve the memory management mystery of ReactiveCocoa 2.5

    RACSubject* subject = [RACSubject subject];
    RACSignal* signal = [RACSignal return:@(1)];
    NSLog(@"Retain count of RACSubject %ld", CFGetRetainCount((__bridge CFTypeRef)subject));
    NSLog(@"Retain count of RACSignal %ld", CFGetRetainCount((__bridge CFTypeRef)signal));
    

    The first line output 1, and the second line output 2. It seems that RACSignal will be retained somewhere, while RACSubject is not. If you don't explicitly retain RACSubject, it will be deallocated when the program exits the current scope.

提交回复
热议问题