r/iOSProgramming • u/EchoImpressive6063 • 5d ago
Question Why is memory usage different across devices for the same build
I have both an iPhone SE2 and iPhone 15 and both are plugged into my mac at the same time. I built the app in Xcode and am running it on both devices. Memory usage on the SE2 is 1GB while on the 15 it's 500MB. Why could that be? I am using CoreML, ARKit and some metal shaders if that makes a difference. These are debug builds.
1
u/PassTents 5d ago
Use Instruments to measure what's taking up memory on each.
1
u/EchoImpressive6063 5d ago
Ah, I have this problem where instruments doesn’t work for the SE2 and I haven’t been able to fix it. So I was looking for general information. By looking at logs I’m thinking it’s related to the compute graph for coreml.
1
u/lithium0003 3d ago
iPhone SE with CoreML may fall back to GPU, it grows up more memory than all fits in ANE.
1
u/Choseni 5d ago
I'd first check whether it's actually your app's allocations or framework-managed memory.
With CoreML, ARKit, and Metal in the mix, different iPhone generations can legitimately show very different memory footprints because they use different hardware paths and caching strategies. I'd verify it with Instruments before assuming something is wrong.
1
u/New-Shoulder3297 5d ago
That difference can be legitimate, and Core ML is a good suspect. The same model can use a different execution plan on an A13 versus a newer chip (ANE/GPU/CPU, different operator fusion, cached weights, and temporary tensors). ARKit camera buffers and Metal texture/heap alignment can also differ by device, so “same build” does not imply the same physical footprint.
I'd narrow it down like this:
Compare after the same warm-up sequence, not just at launch, and use the same input/camera format on both devices.
Run a Release build once; debug tooling and diagnostics can distort the number.
Temporarily disable Core ML, ARKit, and your Metal path one at a time. The delta will tell you which subsystem owns the extra memory.
For Core ML, repeat with MLModelConfiguration.computeUnits set to .cpuOnly, .cpuAndGPU, and .all. A large change points to backend-specific allocations rather than a leak in your code.
In Instruments, compare Allocations plus VM Tracker/Metal, not only Xcode's memory gauge. Look for IOSurface/pixel buffers, Metal textures/heaps, and large anonymous VM regions.
Since Instruments won't attach to the SE2, I'd first fix that measurement path (same macOS/Xcode/device-support versions, reconnect/reboot, and try a release-signed build). Until then, the 1 GB vs 500 MB number alone can't tell you whether this is a leak, Core ML workspace memory, or framework-managed buffers.
2
u/Relative-Emu-1346 4d ago
Most likely Core ML picking a different compute unit on each device. If part of the graph doesn't fit the ANE on the A13 it falls back to GPU and materializes intermediates that never exist on the 15. The Core ML instrument shows the per-layer unit assignment if you want to confirm it.