+1 There’s quite a few of those, I’ve removed some when I encountered them, some of them not so trivial replacement due to local scoping. Jean-Yves Sent from my iPhone
On 5 Apr 2025, at 11:45 am, Chris Dumez via webkit-dev <webkit-dev@lists.webkit.org> wrote:
Hi,
I would like to propose updating the WebKit coding style to recommend avoiding autorelease in Objective C whenever possible, for the following reasons: - Performance reasons: - Cleaning up objects from all over the memory space in an autorelease pool can be slow and can cause memory spikes. - Memory Safety: - Holding a RetainPtr to the object makes lifetime clearer, whereas autorelease pool draining is not as clear and can result in use-after-free bugs. - Easier debugging: - Memory corruption bugs are harder to debug when it happens during autorelease pool drain.
Concretely, this means writing code like this: ``` RetainPtr extensionDatabaseQueueName = adoptNS([[NSString alloc] initWithFormat:@"com.apple.WebKit.WKWebExtensionSQLiteStore.%@", _uniqueIdentifier]); String foo = “foo”_s; [object callWith:foo.createNSString().get()]; URL foo = “https://www.webkit.org”_s; [object callWith:foo.createNSURL().get()]; ``` Instead of: ``` NSString *extensionDatabaseQueueName = [NSString stringWithFormat:@"com.apple.WebKit.WKWebExtensionSQLiteStore.%@", _uniqueIdentifier]; RetainPtr extensionDatabaseQueueName = [NSString stringWithFormat:@"com.apple.WebKit.WKWebExtensionSQLiteStore.%@", _uniqueIdentifier]; String foo = “foo”_s; [object callWith:(NSString *)foo]; // This does autorelease internally. URL foo = “https://www.webkit.org”_s; [object callWith:(NSURL *)foo]; // This does autorelease internally. ```
Example PR: https://github.com/WebKit/WebKit/pull/43656
What do you think?
Thanks, Chris Dumez. _______________________________________________ webkit-dev mailing list webkit-dev@lists.webkit.org https://lists.webkit.org/mailman/listinfo/webkit-dev