# iOS Simulator OOM Under Parallel Agents

## Symptom & Root Cause

Booting multiple stock iOS Simulators simultaneously across parallel coding agents drives macOS into memory compression, causes `CoreSimulatorService` timeouts, and leaves orphaned simulators consuming gigabytes of RAM after test scripts crash. Each stock simulator launches dozens of background daemons irrelevant to app testing, and uncoordinated `simctl boot` calls compete for CPU and disk I/O while repeated `simctl uninstall` and `simctl install` cycles churn `140.5 MB` bundles per state.

## Exact Diagnostic & Fix Commands

Inspect currently booted simulators, their `ri_phys_footprint` physical memory footprint via `xcloom sim status`, and macOS memory pressure:

```sh
# Inspect XCLoom fleet status with accurate ri_phys_footprint (RAM, slim/stock mode, owner agent, orphans)
xcloom sim status

# List all booted simulators
xcrun simctl list devices booted

# Inspect memory pressure on macOS
memory_pressure -Q

# Process discovery only (do not use ps RSS to measure simulator RAM; ps RSS double-counts shared dyld pages)
ps -axo pid,comm | grep -E "launchd_sim|CoreSimulator|SpringBoard" | head -n 20
```

Shut down only the idle simulator UDIDs that your own workflow booted (avoid `shutdown all` on shared machines):

```sh
# Shut down a specific simulator UDID you own
xcrun simctl shutdown <UDID>

# Reap orphaned simulators that were booted by XCLoom only
xcloom sim lease --reap-once --json
```

## How XCLoom Prevents Recurrence

XCLoom manages a built-in slim simulator pool with no external `simslim` tool required. Before boot, it applies a dual-tier categorized `disabled.plist` policy spanning `19` daemon categories (`147` default-disabled / `160` total categorized) while keeping `24` core daemons always protected: `com.apple.assistantd` (disabling it triggers Spotlight memory leaks in the simulator), `com.apple.gamed` (disabling it stalls XCUITest `DTServiceHub` launches), and `com.apple.coredevice.dtuhidd` (needed for CoreSimulator host bridging and HID control, including `iPhone Duo`). Passing `--stock` restores the exact original `disabled.plist` bytes.

- Safe Default (default `xcloom sim boot`, `147` disabled entries; keeps `widgets`, `store`, and `photos` enabled; pass `--stock` to opt out): per-simulator `ri_phys_footprint` drops from `1.88 GiB` to `1.50 GiB` (`-20.3%`, `-0.38 GiB`), live `launchd_sim` processes drop from `213` to `140` (`-34.3%`), and cold boot moves from `2.37s` to `2.94s` (`+0.57s`).
- App-Aware Auto-Slim (`xcloom sim boot --for <App.app | .>`, auto-enabled in `xcloom run --smoke`, `xcloom matrix`, and `xcloom test`): statically inspects entitlements, `Info.plist`, `.appex`, and `LC_LOAD_DYLIB` in `2–15 ms` and disables unused `widgets`, `store`, and `photos` up to `160` entries; on `MinimalApp.app`, footprint drops from `1.70 GiB` to `0.72 GiB` (`-57.3%`; unrounded `1.695 -> 0.724 GiB`, `-0.97 GiB`), live processes drop from `190` to `85` (`-55.3%`), and cold boot moves from `2.49s` to `3.02s` (`+0.53s`).

That `+0.53–0.57s` cold boot overhead comes from pre-boot `disabled.plist` backup and merge plus `launchd_sim` startup adjustment when `147–160` services are masked. To prevent host saturation, XCLoom applies hardware-adaptive concurrency caps (`2` slim slots on 16 GB Macs up to `12` on `128 GB+` Mac Studio), throttles concurrent cold boots (default `2` slim or `1` stock boot, with opt-in queuing via `--wait-secs`), and manages pool leases (`xcloom sim lease`, used automatically by `run`, `matrix`, and `test`) via owner-PID + TTL auto-reaping so crashed agents do not leave leased simulators orphaned. Manual `xcloom sim boot` instances stay running until you call `xcloom sim shutdown`, and externally booted simulators remain untouched unless explicitly adopted with `--adopt`.

## Frequently Asked Questions

### Will XCLoom shut down simulators I opened manually in Xcode or another project?

No. `xcloom sim lease` tracks ownership and only shuts down or reaps simulators booted by XCLoom; externally booted simulators are left untouched unless explicitly shared with `--adopt`.

### How many parallel simulators can my Mac run safely?

XCLoom defaults to hardware-adaptive limits ranging from `2` slim slots on 16 GB Macs up to `12` on `128 GB+` Mac Studio. You can model your exact RAM budget on [/tools/simulator-ram-calculator/](/tools/simulator-ram-calculator/).

### How does XCLoom avoid the 25-minute UI verification bottleneck seen in regression runs?

Instead of running `simctl uninstall` and `simctl install` of a `140.5 MB` `.app` per check (which pushed a separate UI regression log to `25 min` across `19` runs), XCLoom pairs slim simulator leases with `0.36s` (`63 KB`) warm `.dylib` patches and single-RunLoop 4-state UI audits (`xcloom matrix` standalone, defaulting to `light, dark, compact, dark-ax-xxxl` with `--states light,compact,dark-ax-xxxl,rtl` for RTL, or `xcloom canvas matrix-act` on an already-booted instrumented sim defaulting to `Light, 375pt Compact, Dark + AX-XXXL, RTL` in `1.44s` on the full SwiftUI `apple/sample-food-truck` app and `0.064s` [`63.8 ms` wall / `63 ms` probe median] on the minimal UIKit `MatrixSweepOracle` fixture, detecting `UILabel` and Vision-OCR SwiftUI `Text` truncation plus view-tree viewport overflow clipping with `0` leaked simulators).

## Related Links

- [Simulator RAM Calculator](/tools/simulator-ram-calculator/)
- [Why Claude Code Spent 70% of My iOS Sessions Waiting on Xcode](/blog/70-percent-xcode-wait-claude-code-ios/)
- [Xcode DerivedData Locks in Git Worktrees](/errors/xcodebuild-deriveddata-lock-worktree/)
- [All iOS Build & Simulator Errors](/errors/)
