Эх сурвалжийг харах

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

* Fixed memory leak issues

* Fixed memory leak issues

* Fixed crash
svoit 5 жил өмнө
parent
commit
0fba527112

+ 3 - 6
AFNetworking/AFURLSessionManager.m

@@ -531,20 +531,17 @@ static NSString * const AFNSURLSessionTaskDidSuspendNotification = @"com.alamofi
     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];
         }
     }];
 

+ 0 - 1
Example/Today Extension Example/TodayViewController.m

@@ -50,7 +50,6 @@
 - (void)widgetPerformUpdateWithCompletionHandler:(void (^)(NCUpdateResult))completionHandler {
     [Post globalTimelinePostsWithBlock:^(NSArray *posts, NSError *error) {
         if (!error) {
-
             self.post = posts.firstObject;
             [self savePost:self.post];
 

+ 3 - 1
Example/macOS Example/AppDelegate.m

@@ -46,8 +46,10 @@
         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];
     }];
 }