SwiftUI Previews process isolation default changes in Xcode 16 affect memory attribution
0 reputation · 03 Mar 2023, 16:03 UTC
0 reputation · 03 Mar 2023, 16:03 UTC
SwiftUI Previews execution moved out of the Xcode process with process isolation introduced in Xcode 15 and continued in Xcode 16. The default now runs the preview agent in a separate, restartable process for Swift packages and app targets, which changes where preview memory is attributed.
The configuration transition is documented via the PREVIEW_DISABLE_PROCESS_ISOLATION build setting and Preview Canvas options in scheme settings. This creates a compatibility boundary between projects created before the default change and projects created after it, with version and host differences possible.
With the agent lifecycle managed automatically, the documented behavior for teardown timing remains unclear. There is no documented developer control for explicit release of preview agent memory.
What is the documented teardown timing for the preview agent when the canvas is closed or Xcode is idle? Is there a supported way to force explicit teardown of the preview agent process? How does memory accounting differ between the Xcode 15 isolation introduction and the Xcode 16 default for Swift packages?
34775 reputation · 03 Mar 2023, 22:21 UTC
Apple’s documentation does not specify an exact teardown time for the preview‑agent process; the agent is terminated automatically by Xcode when the preview canvas is idle or closed, based on internal heuristics.
There is no public API or build setting to force an immediate teardown; the only supported way to release the agent’s memory is to close the preview canvas tab (or quit Xcode).
Memory attribution changed between Xcode 15 and Xcode 16: Xcode 15 introduced the PREVIEW_DISABLE_PROCESS_ISOLATION flag and allowed isolation for app targets, but Swift packages still ran in‑process unless the flag was toggled manually. Xcode 16 makes process isolation the default for both app targets and Swift packages, so preview memory is now consistently charged to the separate “Xcode‑preview‑agent” process rather than the main Xcode process.
Because the preview agent runs as a separate, restartable daemon, Xcode defers its termination until it determines the preview is no longer needed, which explains the lack of a precise teardown timestamp.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.