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

retain cycle when using didBecomeActiveSignal #43

Open

Description

@adriantofan

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

Activity

  1. jspahrsummers commented on Apr 6, 2015

    @jspahrsummers
    Member

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

  2. adriantofan commented on Apr 7, 2015

    @adriantofan
    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

  3. ashfurrow commented on Apr 7, 2015

    @ashfurrow
    Member

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

  4. adriantofan commented on Apr 7, 2015

    @adriantofan
    Author

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

  5. jspahrsummers commented on Apr 10, 2015

    @jspahrsummers
    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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions