Skip to main content

When Closed WebViews Stay Alive: Investigating WebKit Memory in an Audio Plugin

Reopening a JUCE plugin editor built on WKWebView and Three.js left WebKit processes running. We traced it to a plain Cocoa WKWebView with no JUCE involved, in one specific state of the Mac. The method, the data, and what remains unknown.

Stephane Pericat

Founder & Lead Developer · November 14, 2026 · 13 min read

On this page: The architecture

While developing the interactive interface for an upcoming Shortwav Labs modulation plugin, we built a 3D pedal editor: a Blender model exported as a GLB and rendered with Three.js inside JUCE's WebView integration, with every knob and switch bound to a host parameter.

During qualification, a lifecycle test opened and closed that editor 150 times in quick succession. When it finished, 63 WebKit helper processes were still running, holding 1.76 GB between them, and they stayed until the host quit.

That looks like a memory leak, and for a while we treated it as one. The short version of what we found: a plain WKWebView in a plain NSWindow, with no JUCE and none of our code, does the same thing, but only in one particular state of the Mac. Our first runs happened to be in that state, and we did not yet know it mattered. Along the way we also found a much smaller, unrelated retention in JUCE's WebView teardown. Keeping the two apart was most of the work.

The architecture

The editor builds on the WebView architecture we first used for the editor of Yellow Punch, our overdrive plugin. Everything in this post was measured on the newer editor, not on the released Yellow Punch build:

  • View: JUCE 9's WebBrowserComponent, which is a WKWebView on macOS.
  • Page: TypeScript and Three.js, served from the plugin binary by JUCE's resource provider. No local server, no file paths.
  • Model: a GLB from Blender whose control nodes carry glTF extras (the parameter they drive, rotation limits, rest angle), so the page poses each control without hard-coded geometry.
  • Parameters: JUCE's web relays carry values both ways. Host automation moves the 3D control; dragging it sends a gesture and values to the host. In this editor we drive the relays from a message-thread poll rather than JUCE's stock web attachments, which in our tests allocated on whatever thread changed the parameter, including the audio thread (details).
  • Render on demand: the page draws only when something changes, host-driven redraws are capped at 30 fps, shadow maps are redrawn only when a shadow-casting control moves, and nothing renders while the page is hidden.

The appeal is that one asset drives both the product render and the editor, the GPU does the drawing, and layout and accessibility come from the web platform. The cost is a browser engine inside your plugin. WebKit runs the page in separate processes (a WebContent process for the page, plus GPU and Networking processes that can be shared), and none of them appear in the host's own memory figures.

The first observation

Our test host loads the built plugin, runs a real audio callback and opens the editor in a real NSWindow, as a DAW would. For lifecycle tests it opens and closes the editor on a fixed cadence (120 ms open, 30 ms closed for the rapid case) and samples every WebKit process it started, by process id, twice a second.

  • 50 cycles: at most 4 helpers alive at any time, 2 at the end.
  • 150 cycles: 2–3 helpers for roughly the first hundred cycles (we later pinned this at about 90). Then WebKit stopped retiring them, and 63 processes (1.76 GB) stayed alive through the 40-second hold, exiting only with the host.

Growing helper memory is not, by itself, a plugin leak. WebKit has its own process policies: it can keep processes warm, share them and reclaim them later. To call this a leak in our code we needed memory that never comes back and a cause we could attribute to our code. We had the first, apparently, and not the second.

A third data point narrowed things. Our in-process tests create and destroy editors without ever putting them in a window, and across about 2,800 web views that way there were never more than 4 helpers. That suggested real windows were part of it. We listed three candidates: WebKit's handling of rapidly closed windows, JUCE's window teardown, and our editor.

Every row of that run also recorded a detail we read as a footnote: nobody was at the machine, so the display was asleep and the screen locked. WKWebView had presented no frames at all.

Making the test visible

We repeated the runs in an unlocked session with the display kept awake. Every row now records the session state at both ends, screen lock and display sleep (both readable without privileges through CGSessionCopyCurrentDictionary and CGDisplayIsAsleep), plus the page's own document.hidden.

The problem disappeared. After 150 rapid cycles and a 40-second drain with the host still running, two helpers remained (GPU and Networking) and no WebContent process. The host footprint rose once, by about 23 MB, when WebKit and JavaScriptCore loaded, then stayed flat from cycle 10 to cycle 140.

We tried to reach the hidden state without locking the Mac, by covering the editor with an opaque always-on-top window and by moving it off-screen. In both cases the page stayed visible and animation frames kept running. In our tests, the page became hidden while the display was asleep and the session was locked. We did not test either condition on its own; every hidden run below had both.

Isolating the cause

To reach the hidden state without forcing anything, we released the display-sleep assertion and let the system's own settings act: display sleep, then the lock five minutes later. A script waited for both, and each run recorded them again at its end. Cadence, cycle count and drain were the same as in the visible runs. Then we ran the same test on variants containing less and less of the stack:

Variant (display asleep and locked, 150 rapid cycles)What it containsWebContent alive after drainHelper memory, peak
Full editor, release buildpage, GLB, relays, native integration, teardown workaround611.76 GB
Editor without the GLBthe same, page served without its 3D asset601.73 GB
Editor without our teardown workaroundthe full editor, minus the fix described below601.74 GB
JUCE native integration and resource providerour page, with no relays or editor functions601.72 GB
JUCE resource provider onlyour page in its browser-mock mode, no native integration601.72 GB
Bare JUCE WebBrowserComponentdefault options, about:blank601.74 GB
WKWebView in an NSWindowno JUCE, default configuration, about:blank601.71 GB

The last row is about forty lines of Objective-C++ that open a window, give it a web view with a default configuration, load about:blank and close it on our host's cadence:

// One cycle: a default WKWebView in a plain window
NSWindow* w = [[NSWindow alloc]
    initWithContentRect: NSMakeRect (100, 100, 468, 792)
              styleMask: NSWindowStyleMaskTitled | NSWindowStyleMaskClosable
                backing: NSBackingStoreBuffered
                  defer: NO];
w.releasedWhenClosed = NO;

WKWebView* v = [[WKWebView alloc]
    initWithFrame: NSMakeRect (0, 0, 468, 792)
    configuration: [WKWebViewConfiguration new]];
NSURL* blank = [NSURL URLWithString: @"about:blank"];
[v loadRequest: [NSURLRequest requestWithURL: blank]];
w.contentView = v;
[w makeKeyAndOrderFront: nil];

// 120 ms later: [w close]; w.contentView = nil;
// then 30 ms until the next cycle

Every row behaves the same. That rules out our page, relays and asset, JUCE's destruction order and native integration, our teardown workaround, and our test host's window handling, which the plain control does not use.

The shape of the accumulation

The 300-cycle run of the plain control (no JUCE; display asleep, screen locked) shows the pattern clearly. Samples from its log, with the memory of all WebKit helpers combined:

t (s)  WebContent      RSS
  3.2        1       44 MB
 16.1        1       68 MB
 19.3       16      482 MB  onset
 25.8       51    1,456 MB
 35.4      102    2,878 MB
 45.1      152    4,272 MB
 54.9      202    5,647 MB
 58.1      210    5,891 MB  end
 98.4      210    5,893 MB  +40 s

The onset is near the 90th view, "end" is the last cycle, and the final row is after the 40-second hold: every process is still alive.

On macOS 26.6.2 with WebKit 21624.5.1.11.3, in this state:

  • Onset. For roughly the first 90 views opened in a process, WebKit retires each closed view's WebContent process normally.
  • After the onset, the WebContent process of every closed view stays alive, about 28 MB each. 150 openings left 60. 300 openings left 210, with 5.9 GB of helper memory (5.89 GB for the plain control, 5.91 GB for our full editor).
  • No ceiling observed. The count stopped rising exactly when the cycles stopped.
  • Cadence does not matter. With the editor open 3 s and closed 1 s, the onset came after 330–395 s instead of 19 s, but at about the same opening count, and 150 openings again left 60.
  • Release. In these sustained locked-and-asleep runs, the kept processes were reclaimed only when the process that opened the views exited. A later lock-and-unlock run showed another cleanup path, described in the next section; its trigger is unknown.

One correction belongs in the record. After the first 150-cycle runs we read "60 processes" as a plateau. It is not: 60 is 150 minus 90. Running 300 cycles showed it.

Across a lock and an unlock

Does this matter in an ordinary session, where a DAW stays open while its user locks the Mac and comes back? We answered that with runs in which a person locked and unlocked the Mac themselves. The harness waited for each state and simulated nothing, stopped itself at safety caps (150 WebContent processes or 5 GB), and used validity rules and readouts fixed before the runs.

  • Ordinary use. 100 visible openings, about six and a half minutes locked with no openings, then 150 visible openings after the unlock. The host's WebContent count never exceeded 2.
  • Openings while locked. 60 visible openings, then 120 scripted openings while locked. Processes began to be kept after about the 92nd locked opening, so the visible openings before the lock did not count toward the threshold. 30 were kept (900 MB) for six minutes. When the display woke, with the screen still locked, all 30 were released within about a second, 5.5 s before the unlock. After the unlock, 150 visible openings kept nothing.

The limits matter as much as the results: one machine, one macOS build, one valid run of each kind, and our test host rather than a DAW. We did not isolate what triggered the release (the display waking, the user's input or the lock screen appearing), and the plain WKWebView control was not run through a lock and unlock.

What we concluded, and what we did not

Established: on this macOS build, with the display asleep and the screen locked, WebKit keeps the WebContent process of each closed web view alive once about 90 views have been opened in the process, with no ceiling we could find. It reproduces without JUCE and without our code, and did not occur in any visible run.

Not established: why. We have not identified a mechanism inside WebKit, and we do not claim to know which component is responsible or whether the behaviour is intended. We do not know whether display sleep or the lock is the relevant condition. We have not yet reported it to Apple.

Exposure: in the conditions we tested, reaching it took software opening views on a locked Mac, such as scripted hosts, validators or batch jobs. Ordinary use across a lock and unlock was clean. Beyond those conditions we can neither rule it out nor demonstrate it.

What we did not do: add a plugin-side workaround. Terminating WebKit's helper processes is not a cleanup strategy. We considered keeping one web view alive per plugin instance, so that reopening never creates a new view, and rejected it for now. It is untested against this behaviour, it moves the view's lifetime from the editor to the processor, it could hold hundreds of megabytes while the editor is closed, and it could introduce new host compatibility problems.

A separate, smaller problem in JUCE's teardown

While measuring in-process editor footprint, we found something unrelated and much smaller.

The test itself needed fixing first. Our original loop created, painted and destroyed editors with no autorelease pool and no run loop, and gave anything from +29 MB to −71 MB depending on what ran before it. WebKit autoreleases objects and tears views down asynchronously on the main run loop, so each cycle now runs in an autorelease pool followed by a short run-loop pass. Then we ran controls:

Configuration (in-process, no windows, 400 cycles)Footprint growth
Bare WebBrowserComponent, about:blank0.1–0.2 MB
Resource provider only−0.5 to +0.3 MB
Native integration only2.0–2.5 MB
Native integration and resource provider1.7–1.8 MB
The same, script handler and user script removed before destruction0.0–0.2 MB

The ranges span two runs. Native integration alone accounts for roughly 5–6 kB per cycle; in our full editor before the workaround we recorded about 1.4 MB per 100 cycles, roughly 14 kB per closed editor.

With native integrations enabled, JUCE 9.0.3's WKWebViewImpl constructor registers a script message handler named __JUCE__ on the configuration's user content controller, and adds one user script containing JUCE's integration script plus the editor's own scripts. The destructor detaches the view and clears its delegates, but removes neither:

~WKWebViewImpl() override
{
    WebViewDelegateClass::setConnector (webViewDelegate.get(), nullptr);

    setView (nil);
    [webView.get() setNavigationDelegate: nil];
    [webView.get() setUIDelegate:         nil];
}

The destructor and the registration are unchanged on JUCE's develop branch as of this writing. Our workaround runs in the editor's destructor, on the message thread, before the browser member is destroyed:

void releaseWebViewBridge (juce::WebBrowserComponent& browser)
{
    for (auto* child : browser.getChildren())
    {
        auto* host = dynamic_cast<juce::NSViewComponent*> (child);
        id view = host != nullptr ? (id) host->getView() : nil;

        if (! [view isKindOfClass: [WKWebView class]])
            continue;

        auto* controller = [[(WKWebView*) view configuration]
                                userContentController];
        [controller removeScriptMessageHandlerForName: @"__JUCE__"];
        [controller removeAllUserScripts];
    }
}

It is deliberately narrow, and it relies on an implementation detail: the child NSViewComponent that JUCE uses to host the WKWebView. It has to be revalidated with the controls above on every JUCE upgrade and removed once JUCE does this itself. We have not yet reported this one upstream either.

Do not conflate the two findings. The teardown retention is in-process, kilobytes per editor, visible or not, and fixed. The helper accumulation is in WebKit's processes, about 28 MB per view past the onset, and only in the hidden state. Removing the workaround did not change the accumulation (third row of the isolation table).

Measuring render cost honestly

Most of a WebView editor's cost is invisible to host-side measurements. The numbers below come from a visible session on an Apple M5 Max with a 60 Hz display and a 468 × 792 editor window. The process figures are from the release build; the page timings and frame pacing are from a debug build that reports them from inside the page. They describe our unoptimised prototype asset on that machine, not the intrinsic overhead of WebKit.

Count the helper processes. Our test host compared the plugin's earlier JUCE-painted editor with the WebView editor under identical settings (VST3, 48 kHz, 128-sample buffers):

MeasureJUCE-painted editorWebView editor
Idle: host main-thread CPU0.59 %0.59 %
Idle: WebKit helpersnone3 processes, 577 MB, 4.2 % CPU
60 Hz automation of every parameter: host main-thread CPU12.2 %5.2 %
Same: host process CPU19.7 %11.1 %
Same: WebKit helpersnone3 processes, 613 MB, 38.7 % CPU
Same: audio callback p99.9, % of buffer period5.78 %5.60 %
Deadline misses, every row00

CPU figures are percentages of one core. Reading only the host process, the WebView editor looks cheaper. Counting the helpers, under automation it uses about two and a half times the total CPU of the JUCE-painted editor, mostly outside the host. The audio callback is unaffected either way.

Helper CPU is not GPU time. The GPU helper's CPU time is spent submitting, rasterising and compositing. We could not time GPU work from inside the page: gl.finish() returned in 0–1 ms for a frame of over a million triangles, and a GPU fence placed after the first render signalled at the next frame boundary. So we report frame pacing, and we bound the first visible frame from outside the page by capturing the plugin window repeatedly from launch.

Know what a frame contains. The prototype GLB has 353,660 triangles. A frame that also redraws both shadow maps submits 104 draw calls and 1,049,184 triangles.

Know where the memory goes, and what you have not measured. A rendered editor held roughly 600 MB of helper memory; one that never rendered, because it opened on a locked screen, held about 200 MB. The largest known allocations are the GLB's three 2048 × 4096 PNG textures. three.js uploads each as RGBA8 (4 bytes per pixel, although the PNGs have no alpha channel) with a full mipmap chain: 96 MiB for the three base levels, about 128 MiB with mipmaps. Two 2048² shadow maps and the canvas come on top. Those are the allocations three.js requests, not measured GPU memory, and helper RSS includes much else, so we do not attribute the whole figure to them.

Measure idle and interaction separately. Over 120 idle display frames the editor rendered none. A continuous knob drag rendered 119 of 120 frames, at 17 ms median and 21 ms worst, with no stalls. The first camera orbit after opening stalled once for about 200 ms, rising to 1.09 s with eight editors opening together. We suspect shader or pipeline warm-up, but have not verified it. The GLB loaded and parsed in 179–187 ms, and the first window capture showing the pedal came 461–570 ms after navigation start.

Most of these costs belong to the asset, and the production asset will have its own budget. The method is what carries over.

Lessons

  • Isolate to the smallest reproducible case. Forty lines of Objective-C++ answered a question that no amount of reasoning about our own editor could have.
  • Separate framework behaviour from application behaviour. The bare-component and plain-WKWebView rows turn "not our code" from a hope into a measurement.
  • Measure the host and its helpers, by process id, against a no-editor baseline, because helpers can be shared.
  • Test visible and hidden lifecycles, and record which one you ran. Our first runs were in the one state that triggers the behaviour, and the record of it was the clue.
  • Run past the threshold. A 30- or 50-opening lifecycle test passes in every condition. Ours now runs 150.
  • Distinguish CPU from GPU. Helper CPU tells you what was spent feeding the GPU, not how busy the GPU was.
  • Avoid speculative workarounds. A persistent web view was plausible and unevidenced, and would have changed the lifecycle for every user to address a state most users never reach.
  • Document the environment. OS build, WebKit build and session state accompany every number here, because the most important number changes with the session state.
  • Keep failing evidence, and correct it in the open. The original 63-process result and the misread plateau are part of why the final reading is credible.

Open questions

  • What sets the onset near 90 views, and does it differ on other macOS versions?
  • Is the relevant condition display sleep, the screen lock, or both together?
  • What released the kept processes when the display woke?
  • Does the plain WKWebView control behave the same across a lock and unlock?
  • Is the behaviour the same in commercial DAWs, which may host plugins in separate processes?

The method (session-state recording, controls and cycle counts) is documented in the JUCE WebView reference of our agent skills, so it can be rerun on other machines and macOS versions. The other upstream finding from the same qualification work, a Core Foundation leak in JUCE's Audio Unit wrapper, is written up in Tracking Down a Core Foundation Memory Leak in JUCE's Audio Unit Wrapper.

Back to all posts