XCode swallowing all memory

Lately, XCode's use of memory has resulted in freezing my machine. This tends to occure during compilation, but not only. No such problems from command line or alternative IDE CodebBlocks with same compiler. Any suggestion for troubleshooting?


Developer Information:

Version: 3.2 (10M2309)
Location: /Developer
Applications:
Xcode: 3.2.4 (1708)
Interface Builder: 3.2.4 (804)
Instruments: 2.7 (3014)
Dashcode: 3.0.2 (333)
SDKs:
Mac OS X:
10.5: (9L31a)
10.6: (10M2309)


Activity Monitor for XCode:

Real 2.51GB
Virtual 15GB
Shared 49MB
Private 2.79GB
Virual Private 4.74

MacBook5,1, Mac OS X (10.6.1)

Posted on Mar 3, 2011 1:19 PM

Reply
Question marked as Top-ranking reply

Posted on Mar 4, 2011 2:32 PM

Hi frangipane

frangipane wrote:
"If I were in your position, I would clear out all cache files,"

Specifically, you mean ~/Library/Caches/com.apple.Xcode? FYI 82KB.


You might as well clear out ALL cache files. It won't do any harm and can reclaim some disk space. More information here:
http://hints.macworld.com/article.php?story=20060111202501460

Be sure to reboot immediately after the files have been deleted.

"then delete Xcode preference files,"

Where are they?


Now I look, I see it's just one file:
~/Library/Preferences/com.apple.Xcode.plist

"then run the developer tools de-install script. "

- Where is it?


/Developer/Library/uninstall-devtools

This is Unix command script so you might prefer to execute it from the Terminal program with these commands:
cd /Developer/Library/
./uninstall-devtools

- Wouldn't a de-install script be responsible for the above tasks?!


No. Most uninstallers never bother deleting cache files, and they tend to leave preference files alone so they're still there if the application is re-installed. In this instance, it's quite possible that the cache files and/or the preference files are corrupted so we want to get rid of them just in case.

Good luck

Bob
27 replies
Question marked as Top-ranking reply

Mar 4, 2011 2:32 PM in response to frangipane

Hi frangipane

frangipane wrote:
"If I were in your position, I would clear out all cache files,"

Specifically, you mean ~/Library/Caches/com.apple.Xcode? FYI 82KB.


You might as well clear out ALL cache files. It won't do any harm and can reclaim some disk space. More information here:
http://hints.macworld.com/article.php?story=20060111202501460

Be sure to reboot immediately after the files have been deleted.

"then delete Xcode preference files,"

Where are they?


Now I look, I see it's just one file:
~/Library/Preferences/com.apple.Xcode.plist

"then run the developer tools de-install script. "

- Where is it?


/Developer/Library/uninstall-devtools

This is Unix command script so you might prefer to execute it from the Terminal program with these commands:
cd /Developer/Library/
./uninstall-devtools

- Wouldn't a de-install script be responsible for the above tasks?!


No. Most uninstallers never bother deleting cache files, and they tend to leave preference files alone so they're still there if the application is re-installed. In this instance, it's quite possible that the cache files and/or the preference files are corrupted so we want to get rid of them just in case.

Good luck

Bob

Oct 27, 2011 8:19 AM in response to frangipane

I probably have the same issue. I'm using an iMac running Lion with 8GB of memory, and xcode would swallow +6GB of memory! After doing some research and trials, it looked like xcode would do this with only one particular project. So I went and deleted the projects caches (i.e. ~/Library/Developer/xcode/DerivedData). And Bam! xcode works again with the normal amount of memory needed, about 150 to 200 MB.


Another note is that this project is on a dropbox folder, so I could use it on multiple machines (an iMac and a MB Air). And someone has noted that this may have to do with the Resume feature of Lion. So I also deleted the file: ~/Library/Saved Application State/com.apple.dt.Xcode.Lion.savedState.


Now xcode is working great! Hope this helps someone.


Cheers,

Mota

Mar 1, 2012 4:12 AM in response to MotaSay

There's definitely something to this. I'm pretty new to development, and I recently messed up #include directives which didn't have proper header guards. There was a series of "#include nested too deeply" errors at the top of a list of over 1000 compiler error messages. The debugger console was also running the in bg and I had forgotten about it (though it wasn't doing anything other than waiting for input). I noticed something was amiss when the fan started going nuts and Xcode's memory usage was up around 2GB (I have 4GB RAM in my MB Pro). Force Quit and Quit Process via Activity Monitor were responding so slowly that I had to use killall via the Terminal in order to actually get Xcode to shut down.


More to the point: every attempt to re-open the same project only resulted in the same problem. I fixed the #include directives outside of Xcode in a text editor and compiled with a Makefile. No issues there. Tried re-opening the project in Xcode but the problem happened again, and it was even showing the old compiler warnings for the new files. I suspect Xcode was loading the cache of all those compiler errors in spite of the changes to the files. So, I temporarily removed the offending files from the project directory and reopened the project. Naturally, Xcode didn't find those files and didn't try to load all the associated compiler warnings. With the project open, I moved the files back into their original directory. Xcode found them again, but the error messages were gone and memory usage was normal again.


Message was edited by: mdbraz changed 'warnings' to 'error messages' in last sentence

Apr 8, 2013 12:44 AM in response to frangipane

I have been investigating this issue for some time too. I think one solution (which I need to credit the stackoverflow user justin for) is to set several config values for Xcode. It should be done after quiting the Xcode of course.

In the terminal execute the following commands:

defaults write com.apple.dt.Xcode IDEBuildOperationMaxNumberOfConcurrentCompileTasks 4 


defaults write com.apple.dt.XCode IDEIndexDisable 1

this will prevent indexing and reduce the number of compile tasks. This allowed my Xcode to leave me some RAM for actually doing some work.

to delete these settings, eg indexing:

defaults delete com.apple.dt.XCode IDEIndexDisable

As mentioned, this was discussed in this question.

In addition, cleaning the Xcode cache allowed to reduce the speed that the RAM was eaten with. (at ~/Library/Developer/Xcode/DerivedData - it is at your home dir, and also it is probably hidden, so easier to access with Terminal).

Jun 9, 2011 10:06 AM in response to frangipane

Yep - XCode 4.0.2 just keeps eating memory. Ive got 12GB in a 2011 iMac i5 - after about 4-5 hours, its chock full. Restarting XCode only takes a few seconds and solves the problem.


I have seen XCode release the memory if it sits idle for 1/2 hour or so. Makes me wonder if garbage collection in the XCode app that has run-amok. (none of my projects use garbage collection)

Feb 8, 2013 1:44 AM in response to frangipane

I suddenly got this problem with Xcode 4.6 nose-diving in seconds with a catatrophic memory leak causing me to despair. It seemed to be triggered after I have added an image to some forms. I noticed that I had inadvertently specified the same image (a .jpg) as being both the main image and the highlighted image on the view. Sometimes it was just enough to select the view to trigger meltdown. That seems to have stopped now.


Xcode still munches through memory from time to time but its controllable and you can predict and work around it. I am working on a 4GB machine which probably does not help.

Mar 4, 2011 9:28 AM in response to frangipane

Hi frangipane

Given the problems you're having with Xcode not tabbing properly and now this freezing issue, I'm wondering if your Xcode installation is damaged in some way. There's absolutely no way that Xcode should be causing freezes.

If I were in your position, I would clear out all cache files, then delete Xcode preference files, then run the developer tools de-install script. I would then re-install Xcode and hope this fixes the problem. You probably don't need to download a new version from Apple's web site provided you get no problems when you mount the dmg file.

It's going to take a couple of hours, and when you've done it you may be no better off!

Good luck (you might need it)

Bob

Jun 6, 2011 2:12 AM in response to K T

I have the exact same problem. I tried going form 4GB to 8GB ram on my Mac Book pro but it didn't help. XCode 4 is a huge memory hog. The longer I use it, the more it gobbles up.


The solution, for now, is to relaunch XCode every once in a while. It's fairly fast and really helps with the memory issues.


XCode 4 also uses a lot of CPU. So, doing development on a Mac Mini with 2 GB of RAM must be pretty painful. In my 20+ years of doing development, I have found that developer tools always need high end machines. But, XCode 4 has some serious memory problems right now that I'm sure they are working on. Until then, relaunch it from time to time.

Dec 7, 2011 9:01 AM in response to frangipane

I have only encounted this issue when editing .xib files with Inteface Builder, Since Xcode 4.0 I simply just try to draw everything programmatically instead of using IB, and never running out of memory again unless I have to modify my old projects they still have some .xib file.


The 4.2 new feature storyboard has the same problem probably due to it uses IB as well, or it would be really a time saver for me.

Jul 27, 2012 7:57 AM in response to Maziyar

Mine finally quit doing it - I do not have an exact reason why it stopped, but one of the things I did was clear XCode's cache. It seemed to stop doing it around that time.


http://stackoverflow.com/questions/5714372/how-to-empty-caches-and-clean-all-tar gets-xcode-4


I have not seen this problem in probably 8 months now. Currently on a 21.5-inch, Mid 2011 iMac with 12GB running XCode 4.3.2. Building apps for both OSX and iOS.

Mar 26, 2011 11:15 AM in response to K T

I'm experiencing the exact same problem with a 4GB Macbook Pro.
Free memory goes down to about 10MB and then the swapping starts, causing the slowdown of the whole system, e.g.: simply starting the console or dashboard then takes minutes(!) to load.

A memory upgrade might not fix the issue, because if it's caused by a leak then it will eat up all the resources again as well, no matter how much ram you have available.

In my case it always seems to be InterfaceBuilder related and sometimes switching back to the code view will free up ~2GB of memory, so that the system becomes responsive again rather quickly.
However, in other cases the memory usage doesn't change even after quitting XCode and takes minutes before the GC kicks in to free up some memory again.

It also doesn't matter if I'm just running XCode or have other apps running as well. After a while XCode starts eating up all available memory causing a slowdown again.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

XCode swallowing all memory

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.