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

@weakify(self) optimized out(?) in Release builds xcode 6 beta 6 #80

Open
adriantofan opened this issue Sep 2, 2014 · 6 comments
Open

Comments

@adriantofan
Copy link

Hello everybody,

I have a @weakify(self); inside my viewDidLoad. Later in the code I have a call to

   doCompleted:^{
     @strongify(self);
     [self syncCompletedSuccess:dbPath voicemails:voicemailsPath];
   }]

I've noticed that in Release builds weak_self just after creation is nil as it is nil inside of the do block.

Printing description of self_weak_:
(ATSyncController *const) self_weak_ = <no location, value may have been optimized out>

I will try to replace my doCompleted with a subscribeCompleted in order to clean up a bit, but it doesn't see how it can be the cause of the problem.

Do you have an idea on how this could be fixed ?

Thank you

@kastiglione
Copy link
Collaborator

Are you seeing the same in beta 7?

@adriantofan
Copy link
Author

Yes I have the same problem.

I will try to reproduce it in a clear context knowing that the original one is rather complex.

Unfortunately my storyboard doesn't build in xcode5 so I cannot test it in ordre to pinpoint a xcode6 issue. Still, the problem seems real to me.

@adriantofan
Copy link
Author

Now I can see how the problem arrises. In face self is optimized out ...

I am in viewDidLoad and after a few assignment statements self becomes nil :

  _syncStatus = ATSyncControllerStatusUnkonwn;

After this line self is nil :-( so @weakify(self) cannot work.

I've tried with this just after entering in `viewDidLoaf:

__weak ATSyncController*  SELF = self;

But again SELF is nil.

Somehow it doesn't see as the content of the block might use this weak self.

@kastiglione
Copy link
Collaborator

To get a better idea, can you include the full method here?

@adriantofan
Copy link
Author

Here is the code:

- (void)viewDidLoad{
  [super viewDidLoad];
  _syncStatus = ATSyncControllerStatusUnkonwn;
  _cancelSignal = [[RACReplaySubject alloc] init];
  ATSyncControllerViewModel* viewModel = [[ATSyncControllerViewModel alloc] init];
  _viewModel = viewModel;
  viewModel.cancelSignal = _cancelSignal;
  RAC(self.introView,hidden) = viewModel.introViewHidenSignal;
  RAC(self.syncView,hidden) = viewModel.syncViewHidenSignal;
  RAC(self.statusLabel, text) = viewModel.syncStatusTextSignal;
  @weakify(self)
  [[viewModel.importSignal
  initially:^{
    [[NSFileManager defaultManager] removeItemAtPath:viewModel.dbPath error:nil];
  }]
  subscribeError:^(NSError * error){
    @strongify(self);
    NSLog(@"Error importing sms:%@",error);
    if ([error.domain isEqualToString:RHAddressBookRACSignalErrorDomain]) {
      [self syncCompletedFailure];
    }else{
      [self syncCompletedFailure];
    }
  }
  completed:^{
    @strongify(self);
    [self syncCompletedSuccess:viewModel.dbPath voicemails:viewModel.voiceMailsPath];
    [[NSFileManager defaultManager] removeItemAtPath:kATRemoteZipFilePath error:nil];
  }];
}

@kastiglione
Copy link
Collaborator

After this line self is nil :-(

I have no idea how this would happen.

Have you tried with Xcode 6.0?

If you can make a sample project that reproduces the problem, that could help.

diederich added a commit to cocologics/libextobjc that referenced this issue Jun 28, 2017
Submodule changes to be committed:

* Configuration c8e5527...4ac967d (12):
  > Merge pull request jspahrsummers#80 from cocologics/feature/xcode9-update
  > Merge pull request jspahrsummers#79 from cocologics/feature/xcode9-update
  > Merge pull request jspahrsummers#71 from fabb/analyzer_localized
  > enable CLANG_ANALYZER_NONNULL
  > enable CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION
  > enables SWIFT_TREAT_WARNINGS_AS_ERRORS
  > Merge pull request jspahrsummers#67 from fabb/enable_nullability_completeness_warning
  > Merge pull request jspahrsummers#65 from Abizern/xcode8_debug_flag
  > Merge pull request jspahrsummers#64 from diederich/enableTestability
  > Merge pull request jspahrsummers#63 from diederich/implicitCaptureOfSelf
  > Merge pull request jspahrsummers#62 from calebd/xcode-8-beta-5-warnings
  > Merge pull request jspahrsummers#61 from ikesyo/disable-framework-codesigning
diederich added a commit that referenced this issue Jul 14, 2017
* bumped the xcconfigs to latest version
* fix build on Xcode 9 ('void' missing in strict declaration checking)

Submodule changes to be committed:

* Configuration c8e5527...4ac967d (12):
  > Merge pull request #80 from cocologics/feature/xcode9-update
  > Merge pull request #79 from cocologics/feature/xcode9-update
  > Merge pull request #71 from fabb/analyzer_localized
  > enable CLANG_ANALYZER_NONNULL
  > enable CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION
  > enables SWIFT_TREAT_WARNINGS_AS_ERRORS
  > Merge pull request #67 from fabb/enable_nullability_completeness_warning
  > Merge pull request #65 from Abizern/xcode8_debug_flag
  > Merge pull request #64 from diederich/enableTestability
  > Merge pull request #63 from diederich/implicitCaptureOfSelf
  > Merge pull request #62 from calebd/xcode-8-beta-5-warnings
  > Merge pull request #61 from ikesyo/disable-framework-codesigning
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants