Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

retain cycle when using didBecomeActiveSignal #43

Open
adriantofan opened this issue Apr 3, 2015 · 5 comments
Open

retain cycle when using didBecomeActiveSignal #43

adriantofan opened this issue Apr 3, 2015 · 5 comments
Labels

Comments

@adriantofan
Copy link

Hello,

I have a retain cycle in my code caused by the following setup in viewDidLoad

   [[[[RACSignal
    combineLatest:@[RACObserve(self.viewModel,index),
/*A*/                   self.viewModel.didBecomeActiveSignal]]
/*B                          RACObserve(self.viewModel,active)]]*/
    deliverOnMainThread]
    distinctUntilChanged]
    subscribeNext:^(RACTuple* x) {

The option A is causing a retain cycle so the view model is never released. B works fine. Do you see something wrong with the code or it might be a bug ?

Thank you,
Adrian

@jspahrsummers
Copy link
Member

That sounds like a bug, if true. Could you please distill it down into a minimal test case? 🙏

@adriantofan
Copy link
Author

Yes,
Here is the code:

@interface ViewController:UIViewController
@property (nonatomic,strong,readwrite) RVMViewModel* viewModel;
@end

@implementation ViewController
-(void)viewDidLoad{
  [super viewDidLoad];
  self.viewModel = [[RVMViewModel alloc] init];
  [[[[RACSignal
    combineLatest:@[
/*A */                         self.viewModel.didBecomeActiveSignal]]
/*B                            RACObserve(self.viewModel,active)]] */
    deliverOnMainThread]
    distinctUntilChanged]
    subscribeNext:^(RACTuple* x) {
      NSLog(@"...");
    }];
  self.viewModel.active = YES;
}
@end

I would be happy to investigate further if you can give me any pointer about what might be wrong.

Thank you,
Adrian

@ashfurrow
Copy link
Member

@adriantofan Is that a RACObserve inside another RACObserve? That may be the source of the issue.

@adriantofan
Copy link
Author

@ashfurrow no, that was a typo. Sorry about that

@jspahrsummers
Copy link
Member

Ah, so, didBecomeActiveSignal will send the view model whenever a change occurs. That won't automatically cause a cycle, but it could result in problems if you replay the signal (thus keeping the view model alive), or capture the sent value in a block or something.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants