swift-frontend memory usage

I think I've found a memory leak with GeometryReader. The memory footprint of swift-frontend grows 50gb> with this single line

I have detailed the issue here: https://github.com/Func-Main/swiftui-memory-bug

Is anyone able to confirm? I don't think this is an issue related to the purely to the .aspectRatio modifier, but rather GeometryReader in general.

This image was after 30 seconds

Same issue here on latest release: changing .padding from 10.0 to 10 solved it for me. Of course this isn't helpful if you need a fractional value. Perhaps it is a rounding error causing some memory leak in the code.

It's very bad. I found that if the data read by geometryreader is captured by a func but not used, this problem will occur. Memory occupies 30G quickly, and the hard disk reads and writes a lot. Even if Xcode is turned off, it still doesn't help. You must to click to turn off by yourself!

I encountered this problem of excessive memory usage of Swift-frontend when I declared a variable without an explicit type.

let  defaultMargin = 16.0

When I set it with CGFloat, I don't have the problem any more.

let  defaultMargin: CGFloat = 16.0

I hope this can help.

For anyone else experiencing this issue, i found a workaround. Use your source control to find the specific part of your code that causes the issue. Then try to look if there is a small mistake in your code. If not, try putting your code on another location (helped for me for some SwiftUI code).

i noticed that it looks like the compiler gets stuck on a code mistake, or something like that.

I had this issue with part of my code which had no errors at all. Just moving it did the job for me.

Keep in mind to keep your Activity Monitor open and keep an eye on the two processes that can build up the memory.

This bug seems to have been resolved in Xcode 13.2 beta version. When you exit Xcode 13.1 and run it on Xcode 13.2 beta, the swift-frontend thread temporarily increases and then the memory is released. However, when Xcode 13.1 version is running, the same problem occurs even if it runs at 13.2 beta. Please run only Xcode 13.2 beta and test it.

Can confirm that Xcode 13.2 RC appears to have fixed this bug.

Working on XCode 13.1, Monterey - confirming saw the issue where SourceKitService & swift-frontend memory usage would each explode to around 40GB. 

I saw this issue fairly quickly - within minutes - of using GeometryReader in a project. After going through above thread, I decide to remove the code using GeometryReader, force quit above services, closed and re-opened XCode. 

So far, I do not see any spike in memory in the above services. SourceKitService is at about 70MB, XCode at about 1.11 GB. Launched app on device and, so far, XCode & system are stable with above usage. 

Would love to know what the issue is here

Unfortunately, the issue is still present within XCode 13.2 RC in 1 of my complex iOS projects. I'll reopen the issue report to Apple.

The issue is still present in XCode 13.2 Final Release. This is a show stopper! Apple Devs, please soon fix the issue. Xcode is useless since 2 months.

My project does not build anymore, neither with simulator or real device. Analysing the project does not work neither. Automatically running background tasks e.g. for Canvas prevent from continued software development (without user triggered build functionality). RAM memory consumption grows up to 100 GB and more. Included Swift packages compile correctly, but compilation of own modules lasts for ever in dead loop without compilation warning. There's some long lasting background build activity, if patient, the build process may finish (before the MBP resets). This behaviour is non deterministic: I've experienced the same project may compile/run after a build folder clean without any code change. I was somehow lucky to first progress with XCode 13.2 RC (13C90), but the local workaround does not work anymore. Please help out.

Build succeeded 17/12/2021 19:19 1731.0 seconds !!

Had this issue too, couldn't work at all. Updated to Xcode 13.2.1 (13C100) version. Now everything works as a clock!

I had Xcode 13.2.1 (13C100) and the issue remains. im running a MacBookPro15,1 with bigsur

I'm also having the exact same issue, it shows 50 GB memory usage and asks me to force quit apps to freeup memory. Very strange.

This is absolutely ridiculous, this should be a top priority at Apple. I am running 13.2 and ran into this now. After the restart Xcode pushes my Macbook Pro 2020 16GB to above 100c temps and gets stuck on building. How is this still an issue after so many months?? Now I am forced to downgrade to 12.5.1. Some devs are under a lot of deadline pressure, this is unacceptable for a company such as Apple that prides itself in its developer tools.

My M1 Max laptop with 64GB almost exploded today because of this thing... Look at these numbers :)

swift-frontend memory usage
 
 
Q