Duplicate apps launched when debugging in Xcode?

I’ve noticed a strange bug in Xcode 16 and Swift. When a preview is rendering and hasn’t finished yet and you run an app to debug, Xcode is launching two instances of the app. Has anyone else noticed this issue? If you let the preview finish rendering before running the app, this doesn’t happen. Very odd.

Answered by DTS Engineer in 807739022
Written by emde in 765445021
Has anyone else noticed this issue?

This is one of those “does it really matter?” moments. If this is annoying you, please file a bug about it. Some notes:

  • Our Bug Reporting > Profiles and Logs has advice on how to file bugs against Xcode in general and Swift Previews in particular.

  • It’d be great if you included a project that reproduces the problem. If you can’t share your own project, perhaps try reproducing it with an open source project. Or even an Apple sample.

  • Likewise, a screen recording of the issue would be great.

I’d appreciate you posting your bug number, just for the record

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Written by emde in 765445021
Has anyone else noticed this issue?

This is one of those “does it really matter?” moments. If this is annoying you, please file a bug about it. Some notes:

  • Our Bug Reporting > Profiles and Logs has advice on how to file bugs against Xcode in general and Swift Previews in particular.

  • It’d be great if you included a project that reproduces the problem. If you can’t share your own project, perhaps try reproducing it with an open source project. Or even an Apple sample.

  • Likewise, a screen recording of the issue would be great.

I’d appreciate you posting your bug number, just for the record

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I will file a bug report. Any complex UI that takes more than a few seconds to render the preview will cause this issue in Xcode 16. Below is an example view that takes a while to render in preivew. This allows you to run debug while the preview is still rendering. The result is the app loads twice with two icons in the dock. I'll post a bug number once I submit.

import SwiftUI
struct ComplexView: View {
let itemCount = 10_000
var gradientColors: [Color] = [.blue, .purple, .pink, .red, .orange, .yellow]
var body: some View {
ScrollView {
VStack {
Text("Rendering Complex View")
.font(.largeTitle)
.padding()
// Heavy Custom Graphics and Layered Canvas Drawing
Canvas { context, size in
let gradient = Gradient(colors: gradientColors)
// Correcting the gradient fill
context.fill(Path(ellipseIn: CGRect(x: 0, y: 0, width: size.width, height: size.height)),
with: .linearGradient(gradient, startPoint: .zero, endPoint: CGPoint(x: size.width, y: size.height)))
// Stroked ellipses to add complexity
for i in 1..<50 {
let rect = CGRect(x: CGFloat(i) * 10, y: CGFloat(i) * 10, width: size.width / 2, height: size.height / 2)
context.stroke(Path(ellipseIn: rect), with: .color(.black), lineWidth: 1)
}
}
.frame(height: 500)
.padding()
// Expensive ForEach with Thousands of Views
ForEach(0..<itemCount, id: \.self) { index in
HStack {
Circle()
.fill(gradientColors[index % gradientColors.count])
.frame(width: 30, height: 30)
.shadow(radius: 10)
Text("Item \(index)")
.font(.headline)
.foregroundColor(.primary)
}
.padding(.vertical, 2)
}
}
}
}
}
struct ComplexView_Previews: PreviewProvider {
static var previews: some View {
ComplexView()
}
}

@DTS Engineer

Feedback Assistant filed

FB15436443

And yes, this really matters. Debugging an app with duplicate runtimes is not expected behavior from an IDE. I noticed it the first time I ran a debug session after upgrading. How this made it past Q/A at Apple is beyond comprehension.

It also happens on C++ applications with opencv on with XCode version 16.0 (16A242d) when run in the debugger.

Super annoying as I have to check the PID and then close the other one in Activity Manager. Adds 6 seconds to the debugging cycle.

A workaround is to place a 1 second sleep at the top of the main section of your code.

Data points:

  • In my case I am using c++ with SDL2 which invokes a traditional main() function.
  • The problem did not appear until I started running instruments to hunt down a memory leak.
  • My schemas all pass arguments to the program, but the duplicate app launch does not receive any arguments.

@ProofOfDragons @Max_Dillinger , if you could both use Feedback Assistant and reference my submission, FB15436443, it may help to gain attention of Apple and get this resolved.

Thanks.

I landed here after encountering the same issue and was shocked and dismayed to see DTS saying “does it really matter?” Flippant remark, full stop.

But it’s easy to see how it matters. If you’re measuring performance, good luck since now you have pollution from a second instance of yourself! If you’re debugging something, you have to wonder which of the two instances to kill and which the debugger will actually debug. And, imagine an app that writes to a file at startup (very common, preference files or logs or the list goes on) now suddenly battling another copy of itself. These things all hit me immediately with this.

This is one of those “does it really matter?” moments.

Hi Quinn,

Long time reader first time caller. :)

Kind of surprised to read you asking if this "really matters".

Yes this really matters. People in the thread have touched on why multiple instances being launched is annoying (makes debugging difficult, locks resources causing undesired behaviour, leaves behind terminal windows).

But beyond that: XCode is a piece of software that feels very neglected. It crashes all the time. SwiftUI previews routinely fall over. It feels very neglected.

So Apple pushes a bug. Hey, we're all software developers -- it happens. But to have someone with an Apple logo next to their name come in and say "yeah, the software doesn't work right, but it's not that bad", when XCode already feels like it doesn't get the care and attention it needs doesn't feel great.

12

Yes

Confirmed: I have this issue when debugging an app that makes an OpenGL / GLFW window in XCode 16.2 / Sequoia 15.0. It's certainly a bug, and it's dreadfully confusing, because I'm never sure which app is the one I'm debugging.

As a workaround, sleeping the app in the main function for 1 second, before initializing the window, will prevent the duplicate app launch.

The response from official Apple developers is concerning. Is there a higher-up developer to whom this issue 'will really matter'?

I've got the exact same issue, Xcode launches my app three and sometimes 4 times. When this happens, the debugger does not work at all or maybe I'm using the wrong instance.

The only way to fix it is to restart Xcode. So now every two minutes or so I need to restart.

So yes, it does matter. Xcode is almost unusable these days. It's faster if I boot up a 10 year old machine and use Xcode on that.

Just ran into this myself. First reported here in Oct '24 and here it is, March '25 and still no fix, and the response "does it really matter?". Are you serious!?! YES IT MATTERS!

I'm sorry to say this, but the developer experience within the Apple ecosystem has gone way down hill. Products are frequently delivered 80% percent complete at best, API documentation is often non-existent, and bugs in Apple frameworks and devtools fester for years.

My employer has a product we deliver for Windows, Linux, and Mac. I am a senior developer on the Mac port of our product and have actually contemplated advocating for us to drop Mac support. Developing our product for Mac is by far the most expensive of all three platforms because of exactly these kinds of issues.

I ran into this working on a personal project at home, if this had happed at work it would have played absolute havoc with our unittests and testing automation, and I guarantee it would have mattered!

I know it "does't really matter" but I can confirm for my GLFW / OpenGL project this bug still exists on Xcode 16.2. In my case it opens 3 instances.

I also have the problem with Xcode 16 on Sonoma 14.6.1, and a Swift command-line app that uses SwiftGL.

I randomly get 1, 2 or 3 instances of the executable. Most of the time there are 2 instances on my MacBook Pro, while on my Mac Studio there are usually 3.

This is definitely a quality-of-life issue for me. I spent a half hour wondering why the debugger wouldn't stop at any breakpoints. I finally realized that the debugger was attached to only one of the instances.

Now the work-around is to guess which of the app instances is actually attached to the debugger?

Yikes!

Duplicate apps launched when debugging in Xcode?
 
 
Q