1

I use an ivar in a reactive cocoa's block, set weakify(self) and strongify(self) to break the retain cycle. But when I run the code, It causes a memory leak, the controller doesn't call dealloc method. If I change the ivar to an property, it runs right. I'm so confused about it and search for a long time. please tell me why.

- (void)viewDidLoad {
     [super viewDidLoad];
     ...
     @weakify(self);
     [RACObserve(self, something) subscribeNext:^(id x) {
         @strongify(self);
         [_button setBackgroundColor:[UIColor redColor]];
     }];
}

- (void)dealloc {

}
Monqi
  • 81
  • 1
  • 6

1 Answers1

2

@strongify(self) declare new variable with name self and when you call self.button you use this new variable, _button implicitly use don't overriden self

LDNZh
  • 1,136
  • 8
  • 14
  • `@weakify(self)` declare a weak self, `@strongify(self)` declare a strong self. `self.button` means to use the strong one, but `_button` does't use it. save my day. – Monqi Sep 01 '16 at 10:56