Reputation: 21553
I have a view controller, in which there's two ways to go back.
First scenario goes like this:
RecordVC
-> tells Delegate
to dismissRecordVC:
-> RecordVC
dismissed and deallocated
Second scenario goes like this:
RecordVC
-> tells Delegate
to dismissAndShowVideosForRecordVC:
-> RecordVC
dismissed and VideosTVC
presented BUT RecordVC
is NOT deallocated.
First scenario is triggered like this:
- (IBAction)back:(id)sender {
if ([_chromaKeySessionManager isWriting]) {
[_chromaKeySessionManager cancelWriting];
}
[_chromaKeySessionManager stopRunning];
[delegate dismissRecordVC:self];
}
the delegate method dismissRecordVC:
is this:
- (void)dismissRecordVC:(RecordVC *)vc {
[self dismissModalViewControllerAnimated:YES];
}
If this back:
method is used, then RecordVC is deallocated just fine.
Second scenario is triggered like this:
- (IBAction)goToVideos {
if ([_chromaKeySessionManager isWriting]) {
[_chromaKeySessionManager cancelWriting];
}
[_chromaKeySessionManager stopRunning];
[delegate dismissAndShowVideosForRecordVC:self];
}
and delegate's dismissAndShowVideosForRecordVC:
method:
- (void)dismissAndShowVideosForRecordVC:(RecordVC *)vc {
[self dismissViewControllerAnimated:YES completion:^{
VideosTVC *vc = [[VideosTVC alloc] init];
[[self navigationController] pushViewController:vc animated:YES];
[vc release];
}];
}
So, in this case, RecordVC never gets deallocated. The only difference here is this I am dismissing it with a completion block and pushing another controller.
To me, in both scenarios look the exact same (as far as retaining/releasing goes), except in first one it RecordVC get's deallocated and in latter scenario it never gets deallocated. Weird, and I know I shouldn't say this, but seems to be like an internal leak.
Is there something I am retaining that I am not aware of when using completion block for dismissing? Thanks
Upvotes: 2
Views: 1663
Reputation: 90521
One difference is that the completion block references self
. That causes it to be at least retained until the block fires. Admittedly, after that it ought to be released.
Try creating a local outside of the block to hold [self navigationController]
and then use that local in the block so there's no reference to self
.
I'll also point out that in -dismissAndShowVideosForRecordVC:
you have a parameter and a local with the same name. Shouldn't matter, but maybe there's a compiler bug.
Upvotes: 1