MacOS – Mac swift process blocks system, high memory pressure

macosmemoryswiftxcode

Recently, since XCode 11, my Mac starts a process (it seems like it does so when indexing or building files) called swift and my Mac soon starts to lag. This process gathers a lot of memory (sometimes it gathers up to 70 GB) from my computer and I have to kill the process every time in order to get back to normal and start using my Mac as before.

How do I stop this memory pressure from increasing this much ?

enter image description here

enter image description here

Best Answer

To clean your build in Xcode (under Product menu) and deleting cache in ~/Library/Developer/Xcode/DerivedData/ (not the whole Developer folder, as it has simulators etc. too) was my original suggestion.

Finding on Stack Overflow got me these:

  • Restart your Mac.

  • After making a copy of your project in a safe place, right click on the project file and select "Show Package Contents". Delete the .xcworkspace file and rebuild your project. Use the backup file if it persists.

  • Bugs in Swift which can be triggered by

    • Declaring arrays in multiple lines
    • Programming errors.
    • Several concatenations in one line
    • ...it was caused by a 20 item array literal. Had to switch to different syntax.

and so on..

New ones:

Your best bet is to use search and sort feature on SO, see linked and suggested questions to find problems in your code. Might even want to use source control to move back to the part where it was not problematic. After you've exhausted your search and trials, edit the question, I'd put a bounty. If it is not helpful, ask mods to kindly migrate.