Skip to content
Permalink
Browse files

Fix reference cycle in example, remove unnecessary weak / strong (#4196)

* Fixed memory leak issues

* Fixed memory leak issues

* Fixed crash
  • Loading branch information
svoit authored and jshier committed Jan 5, 2020
1 parent 4743faa commit 0fba52711237096325f4a0cf7e38c4a2cc6472f6
@@ -531,20 +531,17 @@ - (instancetype)initWithSessionConfiguration:(NSURLSessionConfiguration *)config
self.lock = [[NSLock alloc] init];
self.lock.name = AFURLSessionManagerLockName;

__weak typeof(self) weakSelf = self;
[self.session getTasksWithCompletionHandler:^(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks) {

__strong typeof(weakSelf) strongSelf = weakSelf;
for (NSURLSessionDataTask *task in dataTasks) {
[strongSelf addDelegateForDataTask:task uploadProgress:nil downloadProgress:nil completionHandler:nil];
[self addDelegateForDataTask:task uploadProgress:nil downloadProgress:nil completionHandler:nil];
}

for (NSURLSessionUploadTask *uploadTask in uploadTasks) {
[strongSelf addDelegateForUploadTask:uploadTask progress:nil completionHandler:nil];
[self addDelegateForUploadTask:uploadTask progress:nil completionHandler:nil];
}

for (NSURLSessionDownloadTask *downloadTask in downloadTasks) {
[strongSelf addDelegateForDownloadTask:downloadTask progress:nil destination:nil completionHandler:nil];
[self addDelegateForDownloadTask:downloadTask progress:nil destination:nil completionHandler:nil];
}
}];

@@ -50,7 +50,6 @@ - (void)viewWillAppear:(BOOL)animated {
- (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
[Post globalTimelinePostsWithBlock:^(NSArray *posts, NSError *error) {
if (!error) {

self.post = posts.firstObject;
[self savePost:self.post];

@@ -46,8 +46,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification {
self.postsArrayController.content = posts;
}];

__weak __typeof(self)weakSelf = self;
[[NSNotificationCenter defaultCenter] addObserverForName:kUserProfileImageDidLoadNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
[self.tableView reloadData];
__strong __typeof(weakSelf)strongSelf = weakSelf;
[strongSelf.tableView reloadData];
}];
}

0 comments on commit 0fba527

Please sign in to comment.
You can’t perform that action at this time.