Skip to content

Commit

Permalink
Fix reference cycle in example, remove unnecessary weak / strong (AFN…
Browse files Browse the repository at this point in the history
…etworking#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 0fba527
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
9 changes: 3 additions & 6 deletions AFNetworking/AFURLSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}];

Expand Down
1 change: 0 additions & 1 deletion Example/Today Extension Example/TodayViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
4 changes: 3 additions & 1 deletion Example/macOS Example/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}];
}

Expand Down

0 comments on commit 0fba527

Please sign in to comment.