Bug 221932 - Reduce explicit usage of [objC autorelease] in WebKit
Summary: Reduce explicit usage of [objC autorelease] in WebKit
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on: 221914
Blocks:
  Show dependency treegraph
 
Reported: 2021-02-15 15:10 PST by Chris Dumez
Modified: 2021-02-18 22:12 PST (History)
26 users (show)

See Also:


Attachments
Patch (141.12 KB, patch)
2021-02-15 16:28 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (141.11 KB, patch)
2021-02-15 17:28 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (140.26 KB, patch)
2021-02-16 11:48 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (175.36 KB, patch)
2021-02-16 13:23 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Follow-up (27.52 KB, patch)
2021-02-18 14:25 PST, Chris Dumez
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Follow up (27.62 KB, patch)
2021-02-18 14:44 PST, Chris Dumez
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2021-02-15 15:10:20 PST
Reduce explicit usage of [objC autorelease] in WebKit by using RetainPtr<>.
Comment 1 Chris Dumez 2021-02-15 16:28:37 PST
Created attachment 420390 [details]
Patch
Comment 2 Chris Dumez 2021-02-15 17:28:33 PST
Created attachment 420404 [details]
Patch
Comment 3 Chris Dumez 2021-02-16 11:48:23 PST
Created attachment 420513 [details]
Patch
Comment 4 EWS Watchlist 2021-02-16 11:49:08 PST
This patch modifies the inspector protocol generator. Please ensure that you have rebaselined any generator test results (i.e., by running `Tools/Scripts/run-inspector-generator-tests --reset-results`)
Comment 5 Geoffrey Garen 2021-02-16 13:20:39 PST
Comment on attachment 420513 [details]
Patch

r=me -- note the style bot comment about test results
Comment 6 Chris Dumez 2021-02-16 13:23:07 PST
Created attachment 420530 [details]
Patch
Comment 7 EWS 2021-02-16 16:00:08 PST
Committed r272936: <https://commits.webkit.org/r272936>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 420530 [details].
Comment 8 Radar WebKit Bug Importer 2021-02-16 16:02:44 PST
<rdar://problem/74410900>
Comment 9 Darin Adler 2021-02-18 13:51:39 PST
Comment on attachment 420530 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=420530&action=review

Looking back at this to see where we have opportunity to use a little less autorelease.

> Source/JavaScriptCore/API/JSContext.mm:71
> +    return [self initWithVirtualMachine:adoptNS([[JSVirtualMachine alloc] init]).autorelease()];

get()

> Source/JavaScriptCore/API/JSWrapperMap.mm:638
> +    return m_classMap.get()[(id)cls] = adoptNS([[JSObjCClassInfo alloc] initForClass:cls]).autorelease();

get()

> Source/JavaScriptCore/inspector/scripts/codegen/objc_generator.py:408
> +            return 'adoptNS([[%s alloc] initWithJSONObject:%s]).autorelease()' % (objc_class, var_name)

This should be changed to use RetainPtr instead of autorelease.

> Source/WebCore/accessibility/ios/WebAccessibilityObjectWrapperIOS.mm:2550
> +            object = adoptNS([[NSMutableAttributedString alloc] initWithString:[NSString stringWithCharacters:&attachmentChar length:1] attributes:@{ UIAccessibilityTokenAttachment : object }]).autorelease();

Seems like we could use RetainPtr instead of autorelease here.

> Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm:131
> +        @"WebResourceHandler": adoptNS([WebArchiveResourceWebResourceHandler new]).autorelease(),

get()

> Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:923
> +            resourceLoader.URLSession = (NSURLSession *)adoptNS([[WebCoreNSURLSession alloc] initWithResourceLoader:*mediaResourceLoader delegate:resourceLoader.URLSessionDataDelegate delegateQueue:resourceLoader.URLSessionDataDelegateQueue]).autorelease();

get()

> Source/WebCore/platform/ios/WebAVPlayerController.mm:72
> +    self.playerControllerProxy = adoptNS([allocAVPlayerControllerInstance() init]).autorelease();

get()

> Source/WebCore/platform/ios/wak/WAKView.mm:241
> +    [adoptNS([subviewReferences copy]).autorelease() makeObjectsPerformSelector:@selector(removeFromSuperview)];

get()

> Source/WebCore/platform/network/cocoa/WebCoreNSURLSession.mm:666
> +        request = mutableRequest.autorelease();

I think we can use a local RetainPtr instead.

> Source/WebCore/platform/network/mac/ResourceHandleMac.mm:176
> +        nsRequest = copyRequestWithStorageSession(d->m_storageSession.get(), nsRequest).autorelease();

I think we can use a local RetainPtr instead.

> Source/WebCore/platform/network/mac/ResourceHandleMac.mm:183
> +    NSMutableDictionary *streamProperties = streamPropertiesFromClient ? adoptNS([streamPropertiesFromClient mutableCopy]).autorelease() : [NSMutableDictionary dictionary];

I think we can use RetainPtr instead.

> Source/WebKit/UIProcess/API/Cocoa/NSAttributedString.mm:313
> +                finish(retainPtr(attributedString).autorelease(), retainPtr(documentAttributes).autorelease(), nil);

I don’t think we need retain/autorelease here at all.

> Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1219
> +        completionHandler(adoptNS([[WKFindResult alloc] _initWithMatchFound:NO]).autorelease());

get()

> Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1224
> +        handler(adoptNS([[WKFindResult alloc] _initWithMatchFound:found]).autorelease());

get()

> Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:1713
> +        completionHandler(node.autorelease());

I don’t think we need retain/autorelease at all here.

> Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:2580
> +            handler(retainPtr(attributedString.string.get()).autorelease(), retainPtr(attributedString.documentAttributes.get()).autorelease(), nil);

I don’t think we need retain/autorelease here at all.

> Source/WebKit/UIProcess/API/Cocoa/_WKAutomationSession.mm:44
> +    return [self initWithConfiguration:adoptNS([[_WKAutomationSessionConfiguration alloc] init]).autorelease()];

get()

> Source/WebKit/UIProcess/API/Cocoa/_WKInspector.mm:191
> +        capturedBlock(nil, retainPtr(wrapper(API::InspectorExtension::create(protectedExtensionID.get(), protectedSelf->_inspector->extensionController()))).autorelease());

I don’t think we need retain/autorelease at all here.

> Source/WebKit/UIProcess/API/Cocoa/_WKRemoteWebInspectorViewController.mm:171
> +        capturedBlock(nil, retainPtr(wrapper(API::InspectorExtension::create(protectedExtensionID.get(), protectedSelf->m_remoteInspectorProxy->extensionController()))).autorelease());

I don’t think we need retain/autorelease at all here.

> Source/WebKit/UIProcess/API/Cocoa/_WKUserContentExtensionStore.mm:75
> +        completionHandler(contentFilter.autorelease(), toUserContentRuleListStoreError(error));

get()

> Source/WebKit/UIProcess/API/Cocoa/_WKUserContentExtensionStore.mm:83
> +        completionHandler(contentFilter.autorelease(), toUserContentRuleListStoreError(error));

get()

> Source/WebKit/UIProcess/Automation/ios/WebAutomationSessionIOS.mm:135
> +        [eventsToBeSent addObject:adoptNS([[::WebEvent alloc] initWithKeyEventType:WebEventKeyDown timeStamp:CFAbsoluteTimeGetCurrent() characters:characters charactersIgnoringModifiers:unmodifiedCharacters modifiers:m_currentModifiers isRepeating:NO withFlags:inputFlags withInputManagerHint:nil keyCode:keyCode isTabKey:isTabKey]).autorelease()];

get()

> Source/WebKit/UIProcess/Automation/ios/WebAutomationSessionIOS.mm:141
> +        [eventsToBeSent addObject:adoptNS([[::WebEvent alloc] initWithKeyEventType:WebEventKeyUp timeStamp:CFAbsoluteTimeGetCurrent() characters:characters charactersIgnoringModifiers:unmodifiedCharacters modifiers:m_currentModifiers isRepeating:NO withFlags:inputFlags withInputManagerHint:nil keyCode:keyCode isTabKey:isTabKey]).autorelease()];

get()

> Source/WebKit/UIProcess/Automation/ios/WebAutomationSessionIOS.mm:146
> +        [eventsToBeSent addObject:adoptNS([[::WebEvent alloc] initWithKeyEventType:WebEventKeyDown timeStamp:CFAbsoluteTimeGetCurrent() characters:characters charactersIgnoringModifiers:unmodifiedCharacters modifiers:m_currentModifiers isRepeating:NO withFlags:inputFlags withInputManagerHint:nil keyCode:keyCode isTabKey:isTabKey]).autorelease()];

get()

> Source/WebKit/UIProcess/Automation/ios/WebAutomationSessionIOS.mm:147
> +        [eventsToBeSent addObject:adoptNS([[::WebEvent alloc] initWithKeyEventType:WebEventKeyUp timeStamp:CFAbsoluteTimeGetCurrent() characters:characters charactersIgnoringModifiers:unmodifiedCharacters modifiers:m_currentModifiers isRepeating:NO withFlags:inputFlags withInputManagerHint:nil keyCode:keyCode isTabKey:isTabKey]).autorelease()];

get()

> Source/WebKit/UIProcess/Cocoa/WKContactPicker.mm:294
> +        [contacts addObject:contact.autorelease()];

get()
Comment 10 Chris Dumez 2021-02-18 14:25:08 PST
Reopening to attach new patch.
Comment 11 Chris Dumez 2021-02-18 14:25:11 PST
Created attachment 420872 [details]
Follow-up
Comment 12 Chris Dumez 2021-02-18 14:44:36 PST
Created attachment 420874 [details]
Follow up
Comment 13 EWS 2021-02-18 22:12:39 PST
Committed r273128: <https://commits.webkit.org/r273128>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 420874 [details].