From f27f1de1ee8b6fa81f2ace5c816fbc36938b2212 Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Mon, 21 Nov 2016 12:10:42 +0100 Subject: [PATCH] set UiContactCell contact to null when leaving the view to avoid memory leak --- Classes/ContactsListTableView.h | 1 + Classes/ContactsListTableView.m | 9 +++++++++ Classes/ContactsListView.m | 1 + Classes/LinphoneUI/UIContactCell.m | 1 + 4 files changed, 12 insertions(+) diff --git a/Classes/ContactsListTableView.h b/Classes/ContactsListTableView.h index 591c137e4..af5e6ab1b 100644 --- a/Classes/ContactsListTableView.h +++ b/Classes/ContactsListTableView.h @@ -30,5 +30,6 @@ } - (void)loadData; - (void)loadSearchedData; +- (void)removeAllContacts; @end diff --git a/Classes/ContactsListTableView.m b/Classes/ContactsListTableView.m index 9ea61f4f4..a9fc89ef5 100644 --- a/Classes/ContactsListTableView.m +++ b/Classes/ContactsListTableView.m @@ -67,6 +67,15 @@ - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; + [self removeAllContacts]; +} + +- (void)removeAllContacts { + for (NSInteger j = 0; j < [self.tableView numberOfSections]; ++j) { + for (NSInteger i = 0; i < [self.tableView numberOfRowsInSection:j]; ++i) { + [[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:j]] setContact:nil]; + } + } } #pragma mark - diff --git a/Classes/ContactsListView.m b/Classes/ContactsListView.m index 15d5398d5..82d6e7117 100644 --- a/Classes/ContactsListView.m +++ b/Classes/ContactsListView.m @@ -150,6 +150,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void) viewWillDisappear:(BOOL)animated { self.view = NULL; + [self.tableController removeAllContacts]; } #pragma mark - diff --git a/Classes/LinphoneUI/UIContactCell.m b/Classes/LinphoneUI/UIContactCell.m index 0b74e267b..35bbb584a 100644 --- a/Classes/LinphoneUI/UIContactCell.m +++ b/Classes/LinphoneUI/UIContactCell.m @@ -53,6 +53,7 @@ } - (void)dealloc { + self.contact = NULL; [NSNotificationCenter.defaultCenter removeObserver:self]; }