Bug 206077 - MemoryPressureHandler should handle more than one callback
Summary: MemoryPressureHandler should handle more than one callback
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ben Nham
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-01-10 11:00 PST by Ben Nham
Modified: 2020-01-10 11:02 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Nham 2020-01-10 11:00:18 PST
Currently MemoryPressureHandler only stores a single callback lambda. This causes issues with the common pattern of setting the lambda for the singleton MemoryPressureHandler.

For instance, all of these callsites do the equivalent of MemoryPressureHandler::singleton().setLowMemoryHandler in the UI process:

1. Legacy WebView init in WebInstallMemoryPressureHandler
2. WebProcessPool init in WebProcessPool::platformInitialize
3. +[NSAttributedString retrieveOrCreateWebview] used by all of the +[NSAttributedString loadFromHTMLWith...] APIs

So for instance, if your app creates a WKWebView, and then calls +[NSAttributedString loadFromHTMLWithRequest:options:completionHandler:], then the WebProcessPool low memory handler installed by WKWebView gets overwritten by the NSAttributedString low memory handler, which seems undesirable.

There's a FIXME about this in WebProcessPool, so we should probably make it harder to trample on an existing memory pressure handler, or just allow multiple callbacks to be attached to a single memory pressure handler.
Comment 1 Radar WebKit Bug Importer 2020-01-10 11:00:46 PST
<rdar://problem/58484110>