Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix retain cycles #5061

Merged
merged 15 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Riot/Managers/Analytics/DecryptionFailureTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
/**
The delegate object to receive analytics events.
*/
@property (nonatomic) id<MXAnalyticsDelegate> delegate;
@property (nonatomic, weak) id<MXAnalyticsDelegate> delegate;

/**
Report an event unable to decrypt.
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Common/Recents/RecentsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ FOUNDATION_EXPORT NSString *const RecentsViewControllerDataReadyNotification;
/**
Current alert (if any).
*/
UIAlertController *currentAlert;
__weak UIAlertController *currentAlert;

/**
The list of the section headers currently displayed in the recents table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ @interface SegmentedViewController ()
NSLayoutConstraint *leftMarkerViewConstraint;

// Observe kThemeServiceDidChangeThemeNotification to handle user interface theme change.
id kThemeServiceDidChangeThemeNotificationObserver;
__weak id kThemeServiceDidChangeThemeNotificationObserver;
}

@end
Expand Down Expand Up @@ -183,9 +183,13 @@ - (void)viewDidLoad

[self createSegmentedViews];

MXWeakify(self);

// Observe user interface theme change.
kThemeServiceDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kThemeServiceDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {

MXStrongifyAndReturnIfNil(self);

[self userInterfaceThemeDidChange];

}];
Expand Down
18 changes: 14 additions & 4 deletions Riot/Modules/Communities/GroupsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ @interface GroupsViewController ()
BOOL isRefreshPending;

// Observe UIApplicationDidEnterBackgroundNotification to cancel editing mode when app leaves the foreground state.
id UIApplicationDidEnterBackgroundNotificationObserver;
__weak id UIApplicationDidEnterBackgroundNotificationObserver;

// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
id kAppDelegateDidTapStatusBarNotificationObserver;
__weak id kAppDelegateDidTapStatusBarNotificationObserver;

MXHTTPOperation *currentRequest;

Expand All @@ -39,7 +39,7 @@ @interface GroupsViewController ()
UISearchBar *tableSearchBar;

// Observe kThemeServiceDidChangeThemeNotification to handle user interface theme change.
id kThemeServiceDidChangeThemeNotificationObserver;
__weak id kThemeServiceDidChangeThemeNotificationObserver;
}

@end
Expand Down Expand Up @@ -98,11 +98,15 @@ - (void)viewDidLoad
self.groupsTableView.estimatedSectionHeaderHeight = 30;
self.groupsTableView.estimatedSectionFooterHeight = 0;

MXWeakify(self);

// Observe UIApplicationDidEnterBackgroundNotification to refresh bubbles when app leaves the foreground state.
UIApplicationDidEnterBackgroundNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidEnterBackgroundNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {

MXStrongifyAndReturnIfNil(self);

// Leave potential editing mode
[self cancelEditionMode:isRefreshPending];
[self cancelEditionMode:self->isRefreshPending];

}];

Expand All @@ -117,6 +121,8 @@ - (void)viewDidLoad
// Observe user interface theme change.
kThemeServiceDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kThemeServiceDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {

MXStrongifyAndReturnIfNil(self);

[self userInterfaceThemeDidChange];

}];
Expand Down Expand Up @@ -207,9 +213,13 @@ - (void)viewWillAppear:(BOOL)animated
[self.groupsTableView deselectRowAtIndexPath:indexPath animated:NO];
}

MXWeakify(self);

// Observe kAppDelegateDidTapStatusBarNotificationObserver.
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {

MXStrongifyAndReturnIfNil(self);

[self scrollToTop:YES];

}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ final class GroupDetailsCoordinator: GroupDetailsCoordinatorProtocol {
self.groupDetailsViewController = groupDetailsViewController
}

deinit {
groupDetailsViewController.destroy()
}

// MARK: - Public

func start() {
Expand Down
2 changes: 1 addition & 1 deletion Riot/Modules/Contacts/ContactsTableViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
/**
The delegate for the view controller.
*/
@property (nonatomic) id<ContactsTableViewControllerDelegate> contactsTableViewControllerDelegate;
@property (nonatomic, weak) id<ContactsTableViewControllerDelegate> contactsTableViewControllerDelegate;

@end

12 changes: 10 additions & 2 deletions Riot/Modules/Contacts/ContactsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ @interface ContactsTableViewController () <FindYourContactsFooterViewDelegate, S
/**
Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
*/
id kAppDelegateDidTapStatusBarNotificationObserver;
__weak id kAppDelegateDidTapStatusBarNotificationObserver;

/**
Observe kThemeServiceDidChangeThemeNotification to handle user interface theme change.
*/
id kThemeServiceDidChangeThemeNotificationObserver;
__weak id kThemeServiceDidChangeThemeNotificationObserver;
}

@property (nonatomic, strong) FindYourContactsFooterView *findYourContactsFooterView;
Expand Down Expand Up @@ -102,9 +102,13 @@ - (void)viewDidLoad
self.contactsTableView.tableFooterView = [[UIView alloc] init];
self.contactsAreFilteredWithSearch = NO;

MXWeakify(self);

// Observe user interface theme change.
kThemeServiceDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kThemeServiceDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {

MXStrongifyAndReturnIfNil(self);

[self userInterfaceThemeDidChange];

}];
Expand Down Expand Up @@ -158,10 +162,14 @@ - (void)viewWillAppear:(BOOL)animated

// Screen tracking
[[Analytics sharedInstance] trackScreen:_screenName];

MXWeakify(self);

// Observe kAppDelegateDidTapStatusBarNotification.
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {

MXStrongifyAndReturnIfNil(self);

[self.contactsTableView setContentOffset:CGPointMake(-self.contactsTableView.adjustedContentInset.left, -self.contactsTableView.adjustedContentInset.top) animated:YES];

}];
Expand Down
14 changes: 11 additions & 3 deletions Riot/Modules/Contacts/Details/ContactDetailsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ @interface ContactDetailsViewController () <RoomMemberTitleViewDelegate>
/**
Observe UIApplicationWillChangeStatusBarOrientationNotification to hide/show bubbles bg.
*/
id UIApplicationWillChangeStatusBarOrientationNotificationObserver;
__weak id UIApplicationWillChangeStatusBarOrientationNotificationObserver;

/**
The observer of the presence for matrix user.
*/
id mxPresenceObserver;
__weak id mxPresenceObserver;

/**
List of the basic actions on this contact.
Expand All @@ -79,7 +79,7 @@ Current alert (if any).
/**
Observe kThemeServiceDidChangeThemeNotification to handle user interface theme change.
*/
id kThemeServiceDidChangeThemeNotificationObserver;
__weak id kThemeServiceDidChangeThemeNotificationObserver;

/**
The current visibility of the status bar in this view controller.
Expand Down Expand Up @@ -182,9 +182,13 @@ - (void)viewDidLoad
self.bottomImageView.hidden = (orientation.integerValue == UIInterfaceOrientationLandscapeLeft || orientation.integerValue == UIInterfaceOrientationLandscapeRight);
}];

MXWeakify(self);

// Observe user interface theme change.
kThemeServiceDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kThemeServiceDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {

MXStrongifyAndReturnIfNil(self);

[self userInterfaceThemeDidChange];

}];
Expand Down Expand Up @@ -379,9 +383,13 @@ - (void)registerOnContactChangeNotifications
// Be warned when the thumbnail is updated
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onThumbnailUpdate:) name:kMXKContactThumbnailUpdateNotification object:nil];

MXWeakify(self);

// Observe contact presence change
mxPresenceObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXKContactManagerMatrixUserPresenceChangeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {

MXStrongifyAndReturnIfNil(self);

NSString* matrixId = self.firstMatrixId;

if (matrixId && [matrixId isEqualToString:notif.object])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ final class EnterNewRoomDetailsViewController: UIViewController {

var section3: Section?
if RiotSettings.shared.roomCreationScreenAllowEncryptionConfiguration {
let row_3_0 = Row(type: .withSwitch(isOn: viewModel.roomCreationParameters.isEncrypted, onValueChanged: { (theSwitch) in
self.viewModel.roomCreationParameters.isEncrypted = theSwitch.isOn
let row_3_0 = Row(type: .withSwitch(isOn: viewModel.roomCreationParameters.isEncrypted, onValueChanged: { [weak self] (theSwitch) in
self?.viewModel.roomCreationParameters.isEncrypted = theSwitch.isOn
}), text: VectorL10n.createRoomEnableEncryption, accessoryType: .none) {
// no-op
}
Expand All @@ -117,11 +117,20 @@ final class EnterNewRoomDetailsViewController: UIViewController {

var section4: Section?
if RiotSettings.shared.roomCreationScreenAllowRoomTypeConfiguration {
let row_4_0 = Row(type: .default, text: VectorL10n.createRoomTypePrivate, accessoryType: viewModel.roomCreationParameters.isPublic ? .none : .checkmark) {
let row_4_0 = Row(type: .default, text: VectorL10n.createRoomTypePrivate, accessoryType: viewModel.roomCreationParameters.isPublic ? .none : .checkmark) { [weak self] in
guard let self = self else {
return
}

self.viewModel.roomCreationParameters.isPublic = false
self.updateSections()
}
let row_4_1 = Row(type: .default, text: VectorL10n.createRoomTypePublic, accessoryType: viewModel.roomCreationParameters.isPublic ? .checkmark : .none) {
let row_4_1 = Row(type: .default, text: VectorL10n.createRoomTypePublic, accessoryType: viewModel.roomCreationParameters.isPublic ? .checkmark : .none) { [weak self] in

guard let self = self else {
return
}

self.viewModel.roomCreationParameters.isPublic = true
self.updateSections()
// scroll bottom to show user new fields
Expand Down Expand Up @@ -149,8 +158,8 @@ final class EnterNewRoomDetailsViewController: UIViewController {
}

if viewModel.roomCreationParameters.isPublic {
let row_5_0 = Row(type: .withSwitch(isOn: viewModel.roomCreationParameters.showInDirectory, onValueChanged: { (theSwitch) in
self.viewModel.roomCreationParameters.showInDirectory = theSwitch.isOn
let row_5_0 = Row(type: .withSwitch(isOn: viewModel.roomCreationParameters.showInDirectory, onValueChanged: { [weak self] (theSwitch) in
self?.viewModel.roomCreationParameters.showInDirectory = theSwitch.isOn
}), text: VectorL10n.createRoomShowInDirectory, accessoryType: .none) {
// no-op
}
Expand Down Expand Up @@ -389,7 +398,10 @@ extension EnterNewRoomDetailsViewController: UITableViewDataSource {
cell.mxkLabel.text = row.text
cell.mxkSwitch.isOn = isOn
cell.mxkSwitch.removeTarget(nil, action: nil, for: .valueChanged)
cell.mxkSwitch.vc_addAction(for: .valueChanged) {
cell.mxkSwitch.vc_addAction(for: .valueChanged) { [weak cell] in
guard let cell = cell else {
return
}
onValueChanged?(cell.mxkSwitch)
}
cell.mxkLabelLeadingConstraint.constant = cell.vc_separatorInset.left
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
/**
The delegate for the view controller.
*/
@property (nonatomic) id<JitsiViewControllerDelegate> delegate;
@property (nonatomic, weak) id<JitsiViewControllerDelegate> delegate;

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@
/**
The delegate.
*/
@property (nonatomic) id<RoomMemberTitleViewDelegate> delegate;
@property (nonatomic, weak) id<RoomMemberTitleViewDelegate> delegate;

@end
2 changes: 1 addition & 1 deletion Riot/Modules/Room/Members/RoomParticipantsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
/**
The delegate for the view controller.
*/
@property (nonatomic) id<RoomParticipantsViewControllerDelegate> delegate;
@property (nonatomic, weak) id<RoomParticipantsViewControllerDelegate> delegate;

/**
Returns the `UINib` object initialized for a `RoomParticipantsViewController`.
Expand Down
9 changes: 7 additions & 2 deletions Riot/Modules/Room/RoomViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -2353,11 +2353,14 @@ - (void)showPreviewHeader:(BOOL)isVisible

if (isVisible)
{
previewHeader = [PreviewRoomTitleView roomTitleView];
PreviewRoomTitleView *previewHeader = [PreviewRoomTitleView roomTitleView];
previewHeader.delegate = self;
previewHeader.tapGestureDelegate = self;
previewHeader.translatesAutoresizingMaskIntoConstraints = NO;
[self.previewHeaderContainer addSubview:previewHeader];

self->previewHeader = previewHeader;

// Force preview header in full width
NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:previewHeader
attribute:NSLayoutAttributeLeading
Expand Down Expand Up @@ -5398,7 +5401,7 @@ - (void)showEncryptionInformation:(MXEvent *)event
// Remove potential existing subviews
[self dismissTemporarySubViews];

encryptionInfoView = [[EncryptionInfoView alloc] initWithEvent:event andMatrixSession:self.roomDataSource.mxSession];
EncryptionInfoView *encryptionInfoView = [[EncryptionInfoView alloc] initWithEvent:event andMatrixSession:self.roomDataSource.mxSession];

// Add shadow on added view
encryptionInfoView.layer.cornerRadius = 5;
Expand All @@ -5408,6 +5411,8 @@ - (void)showEncryptionInformation:(MXEvent *)event
// Add the view and define edge constraints
[self.view addSubview:encryptionInfoView];

self->encryptionInfoView = encryptionInfoView;

[self.view addConstraint:[NSLayoutConstraint constraintWithItem:encryptionInfoView
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
Expand Down
Loading