Safari optimized flow should be releasing viewer to prevent memory growth with subseq...
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 May 2018 11:30:04 +0000 (11:30 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 17 May 2018 11:30:04 +0000 (11:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185722
<rdar://problem/40247351>

Reviewed by Antoine Quint.

I made a rookie mistake in the original patch: I was holding a strong
reference to "self" in a block, which was causing a retain cycle.
Replace that with a WeakObjCPtr.

* UIProcess/Cocoa/SystemPreviewControllerCocoa.mm:
(-[_WKPreviewControllerDataSource previewController:previewItemAtIndex:]):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@231893 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Cocoa/SystemPreviewControllerCocoa.mm

index 37e0a72..da69cea 100644 (file)
@@ -1,3 +1,18 @@
+2018-05-17  Dean Jackson  <dino@apple.com>
+
+        Safari optimized flow should be releasing viewer to prevent memory growth with subsequent launches/closes
+        https://bugs.webkit.org/show_bug.cgi?id=185722
+        <rdar://problem/40247351>
+
+        Reviewed by Antoine Quint.
+
+        I made a rookie mistake in the original patch: I was holding a strong
+        reference to "self" in a block, which was causing a retain cycle.
+        Replace that with a WeakObjCPtr.
+
+        * UIProcess/Cocoa/SystemPreviewControllerCocoa.mm:
+        (-[_WKPreviewControllerDataSource previewController:previewItemAtIndex:]):
+
 2018-05-16  Brent Fulgham  <bfulgham@apple.com>
 
         REGRESSION(r229093)[macOS] Allow network-outbound for syslog use
index cc014d4..3f4e9d5 100644 (file)
@@ -29,8 +29,8 @@
 #if USE(SYSTEM_PREVIEW)
 
 #import "APIUIClient.h"
+#import "WeakObjCPtr.h"
 #import "WebPageProxy.h"
-
 #import <MobileCoreServices/MobileCoreServices.h>
 #import <QuickLook/QuickLook.h>
 #import <UIKit/UIViewController.h>
@@ -87,9 +87,10 @@ SOFT_LINK_CLASS(QuickLook, QLItem);
     _item = adoptNS([allocQLItemInstance() initWithPreviewItemProvider:_itemProvider.get() contentType:contentType previewTitle:@"Preview" fileSize:@(0)]);
     [_item setUseLoadingTimeout:NO];
 
-    [_itemProvider registerItemForTypeIdentifier:contentType loadHandler:^(NSItemProviderCompletionHandler completionHandler, Class expectedValueClass, NSDictionary * options) {
-        // This will get called once the download completes.
-        self.completionHandler = completionHandler;
+    WebKit::WeakObjCPtr<_WKPreviewControllerDataSource> weakSelf { self };
+    [_itemProvider registerItemForTypeIdentifier:contentType loadHandler:[weakSelf = WTFMove(weakSelf)] (NSItemProviderCompletionHandler completionHandler, Class expectedValueClass, NSDictionary * options) {
+        if (auto strongSelf = weakSelf.get())
+            [strongSelf setCompletionHandler:completionHandler];
     }];
     return _item.get();
 }