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
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"

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.

Yes

Duplicate apps launched when debugging in Xcode?
 
 
Q