App extension - Improvement: Reduce memory consumption.

Force the ShareExtensionManager to release the primary view controller when the action is completed.

We observed that `dealloc` is called for this view controller when the request is cancelled with error (`cancelRequestWithError`), but it is not called when the request is completed (`completeRequestReturningItems`).
This commit is contained in:
Giom Foret
2017-08-25 11:55:37 +02:00
parent 84f3aefac4
commit be2fe8fea9
6 changed files with 79 additions and 22 deletions
@@ -30,6 +30,8 @@
@property (nonatomic) SegmentedViewController *segmentedViewController;
@property (nonatomic) id shareExtensionManagerDidChangeMXSessionObserver;
@end
@@ -42,7 +44,7 @@
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserverForName:kShareExtensionManagerDidChangeMXSessionNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
self.shareExtensionManagerDidChangeMXSessionObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kShareExtensionManagerDidChangeMXSessionNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
[self configureViews];
@@ -51,12 +53,21 @@
[self configureViews];
}
#pragma mark - Private
- (void)configureViews
- (void)destroy
{
self.masterContainerView.layer.cornerRadius = 7;
[super destroy];
if (self.shareExtensionManagerDidChangeMXSessionObserver)
{
[[NSNotificationCenter defaultCenter] removeObserver:self.shareExtensionManagerDidChangeMXSessionObserver];
self.shareExtensionManagerDidChangeMXSessionObserver = nil;
}
[self resetContentView];
}
- (void)resetContentView
{
// Empty the content view
NSArray *subviews = self.contentView.subviews;
for (UIView *subview in subviews)
@@ -67,10 +78,21 @@
// Release the current segmented view controller if any
if (self.segmentedViewController)
{
[self.segmentedViewController removeFromParentViewController];
// Release correctly all the existing data source and view controllers.
[self.segmentedViewController destroy];
self.segmentedViewController = nil;
}
}
#pragma mark - Private
- (void)configureViews
{
self.masterContainerView.layer.cornerRadius = 7;
[self resetContentView];
if ([ShareExtensionManager sharedManager].mxSession)
{