Memory problem on Xcode 13 and 13.1

I experienced a frustrating problem today wither with Xcode 13 and Xcode 13.1 rc that I have downloaded to test if the problem was presente also in the new version With a certain file Xcode sourcekitservice daemon went to a staggering 60-70 gb of memory causing the MacBook Pro m1 to freeze after a memory warning. After some investigation I found a weird problem (already signaled to apple bug reporting) with GeometryReader and frame.

//////

//////  SwiftUIView.swift

//////  ArteIncisa Evolution

//////

//////  Created by Lorenzo Malaguti on 16/06/21.

//////  Copyright © 2021 Nas-Tech. All rights reserved.

//////

////

import SwiftUI

//



struct BugTitolo: View {

    @State var title:String

    var body: some View {

        Text(title)

            //.font(.custom("INCIMAR Latino 221D1 v.3.0", size: 30))

            .foregroundColor(.white)

            .shadow(color: .black, radius: 2, x: /*@START_MENU_TOKEN@*/0.0/*@END_MENU_TOKEN@*/, y: /*@START_MENU_TOKEN@*/0.0/*@END_MENU_TOKEN@*/)

            .padding(.horizontal, 25)

            .modifier(containerRow(backTexture: "ardesia"))

    }

}









struct BugView: View {

    @Binding var isPresented:Bool

    @State var cfg_Account:Bool = false

    @State var cfg_Elements:Bool = false

//

    let btnHeight:CGFloat = 50



    let btnWidthMultiplier = 0.47

    

    func GetColumnWitdh(screenwidth:CGFloat)->CGFloat

    {

        return screenwidth*btnWidthMultiplier

    }

    

    var body: some View {

        GeometryReader{geom in

            ZStack{

                Image("back.003")

                    .resizable()

                    .blur(radius: 3)

                    .edgesIgnoringSafeArea(/*@START_MENU_TOKEN@*/.all/*@END_MENU_TOKEN@*/)

                

                VStack{

                    NavigationLink("account",

                                   destination: cfgAccountView(isPresented: $cfg_Account),

                                   isActive: $cfg_Account)

                    NavigationLink("account",

                                   destination: cfgElementiView(isPresented: $cfg_Elements),

                                   isActive: $cfg_Elements)

                }

                .hidden()

                

                // pulsante di ritorno e testo titolo-----------------------

                VStack{

                    HStack{

                        Button(action:  {

                            isPresented=false

                        }, label: {

                            Image(systemName: "chevron.backward.circle")

                                .resizable()

                                .modifier(iconModifier())

                        })

                        Spacer()

                        //Text( "Configurazione Arte Incisa")

                        BugTitolo(title: "Configurazione Arte Incisa")

                        Spacer()

                    }

                    // pulsante di ritorno e testo titolo-----------------------

                    Spacer()

                    HStack{

                        VStack{

                            Button(action: {



                            }, label: {

                                Text("Account Utente")

                                    .foregroundColor(Color.black)

                                

                                // ***** THIS LINE DOES NOT GENERATE THE MEMORY OVERFLOW

                                    .frame(width: geom.size.width*0.47, height: btnHeight, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)

                                    

                                // ***** IF YOU COMMENT THE PREVIOUS LINE AND UNCOMMENT THIS ONE A MEMORY PROBLEM WILL ARISE

                                //.frame(width: geom.size.width*btnWidthMultiplier, height: btnHeight, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)

                                

                                // ***** IF YOU COMMENT THE PREVIOUS LINE AND UNCOMMENT THIS ONE THERE WILL BE NO PROBLEM

                                //.frame(width: GetColumnWitdh(screenwidth: geom.size.width), height: btnHeight, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)

                                    .contentShape(Rectangle())



                            })

                        }

                    }

                }

                .navigationBarTitle("", displayMode:.inline)

                .navigationBarBackButtonHidden(true)

                .navigationBarHidden(true)

                .navigationViewStyle(.stack)

                

                

            }



        }

        

    }

}





@available(iOS 15.0, *)

struct BugView_Previews: PreviewProvider {

    static var previews: some View {

        Group{

                NavigationView{

                    BugView(isPresented: .constant(true))

                }

                .navigationViewStyle(.stack)



            .previewDevice("iPad Pro (9.7-inch)")

            .previewInterfaceOrientation(.landscapeLeft)



        }



    }

}

you will see in this code three .frame commands. if you comment and uncomment these leaving only one active you will see that sourcekitservice will grow exponentially (beware, you could be obliged to restart your Mac by keeping pressed the power button) This behavior is really strange, and based on how you do the multiplication the system became unstable. Does it happen also to other? Could you try to load this in Xcode and test it?

  • if you specify the type :CGFloat in the let variable seems that the service doesn't grow up exponentially

Add a Comment

Replies

Thank you for posting this. It helped with my almost identical problem, except I had

@State private var nodeStyle = NodeViewStyle.circles

which needed to change to

@State private var nodeStyle: NodeViewStyle = .circles

Apparently, as you noted, type must be explicitly declared before assignment

This isn’t all of it. It seems there are several triggers. Making it more complicated, there may be a little tolerance. Perhaps one can have several of these ‘bad’ statements in one’s SwiftUI code before Xcode gets out of control?

The statement or construction that triggers this exponential growth in memory usage will be the one of the several possible triggers one adds to one’s code last, making the ‘cause’ appear a little bit random 😦

I am still working on this…