Xcode 使用大内存,吃掉 ram 中的所有内存

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12295113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:25:29  来源:igfitidea点击:

Xcode uses big memory, eats all memory in ram

xcodemacos

提问by user1651186

I use Xcode on my mac, which has 8GB ram. When I open Xcode and don`t open any project and wait about 2 minutes, Xcode eats all the memory in ram, (4GB, 5GB...)

我在我的 mac 上使用 Xcode,它有 8GB 内存。当我打开 Xcode 并且不打开任何项目并等待大约 2 分钟时,Xcode 吃掉了 ram 中的所有内存,(4GB、5GB ...)

Can anybody tell me why and how to fix this?

谁能告诉我为什么以及如何解决这个问题?

回答by Ole

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

我也一直在研究这个问题一段时间。我认为一种解决方案(我需要归功于用户justin)是为 Xcode 设置几个配置值。当然,它应该在退出 Xcode 后完成。

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.

这将阻止索引并减少编译任务的数量。这允许我的 Xcode 为我留下一些 RAM 用于实际做一些工作。

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).

此外,清理 Xcode 缓存可以降低 RAM 被吃掉的速度。(在 ~/Library/Developer/Xcode/DerivedData - 它在您的主目录中,而且它可能是隐藏的,因此更容易通过终端访问)。

Edit/Update:

编辑/更新:

Apparently, this helps with the memory issue (although still need to restart Xcode regularly). However you are loosing some nice-to-haves: instant error checking, control-drag-and-drop IBOutlet adding to the controller header (need to do it the old way - type in and then connect), probably some other helpful features that come with indexing. So be aware.

显然,这有助于解决内存问题(尽管仍然需要定期重新启动 Xcode)。但是,您失去了一些不错的功能:即时错误检查、控制拖放 IBOutlet 添加到控制器标头(需要以旧方式进行 - 输入然后连接),可能还有其他一些有用的功能带有索引。所以要注意。

回答by Irina

found a temporary solution here

这里找到了一个临时解决方案

Run that command every once in a while and it helps with my 8GB

每隔一段时间运行一次该命令,它对我的​​ 8GB 有帮助

回答by Mark McCorkle

I'm surprised I haven't read the real answer/problem here although there is no solution. I see you mentioned you don't even have to open a project but generally the problem occurs when using storyboards. I've confirmed this, sent examples to Apple, filed bug reports, waited for new releases, nothing yet. Somewhere down the line there is a leak when editing storyboard views. If you are editing raw code you will never see the ram usage increase but the second you begin editing a storyboard with multiple views and segues the problem arises. I currently run 24GB of ram and it can be consumed in less than an hour when editing views in a storyboard. Like others have mentioned, the only solution is to restart Xcode. Simply closing the project is not good enough.

我很惊讶我还没有在这里阅读真正的答案/问题,尽管没有解决方案。我看到你提到你甚至不必打开一个项目,但通常在使用故事板时会出现问题。我已经确认了这一点,向 Apple 发送了示例,提交了错误报告,等待了新版本,但还没有。在编辑故事板视图时,某处存在泄漏。如果您正在编辑原始代码,您将永远不会看到 ram 使用量增加,但是当您开始编辑具有多个视图的故事板时,问题就会出现。我目前运行 24GB 的内存,在故事板中编辑视图时,它可以在不到一个小时的时间内消耗掉。就像其他人提到的那样,唯一的解决方案是重新启动 Xcode。简单地关闭项目是不够的。

回答by vedrano

I faced the same problem, but in correlation to Interface Builder and Storyboard access.

我遇到了同样的问题,但与 Interface Builder 和 Storyboard 访问相关。

After some thinking, it becomes clear that after Storyboard file in my project enlarged to some amount (currently about 1.5MB on disk), XCode and IB have problem.

经过一些思考,很明显,在我的项目中的 Storyboard 文件放大到一定数量后(目前磁盘上大约 1.5MB),XCode 和 IB 有问题。

While changing text in some (e.g. IBLabel) object, it needs about 0.5 seconds for each letter, what gives 3 seconds for a change of 6 character word. That slows me a lot.

在更改某些(例如 IBLabel)对象中的文本时,每个字母大约需要 0.5 秒,而更改 6 个字符的单词需要 3 秒。这让我慢了很多。

XCode restart helps and releases all occupied memory...until next working session.

XCode 重启有助于并释放所有占用的内存......直到下一个工作会话。

I have strong impression that IB makes undo buffer after each change (e.g. change single letter) because after each single change, memory footprint enlarges for about 20 MB (probably Storyboard size in RAM, on disk is 1.5 MB).

我有强烈的印象,IB 在每次更改(例如更改单个字母)后都会创建撤消缓冲区,因为在每次更改后,内存占用增加约 20 MB(可能在 RAM 中的 Storyboard 大小,在磁盘上为 1.5 MB)。

And after XCode restart, undo buffer has gone, and some memory has accordingly released.

并且在 XCode 重启后,undo 缓冲区消失了,相应地释放了一些内存。

I would like to know a way to limit undo buffer size, and test it with that smaller size.

我想知道一种限制撤消缓冲区大小的方法,并使用较小的大小对其进行测试。

Configuration is: Mac Mini, 4 GB RAM, OS X 10.8.3, XCode 4.6, XCode 4.6.1, XCode 4.6.2

配置为:Mac Mini、4 GB RAM、OS X 10.8.3、XCode 4.6、XCode 4.6.1、XCode 4.6.2

I am currently back to XCode 4.5 and situation seems a little bit better but problem is still here. I suppose this version has less features than 4.6 and according that difference it uses less memory.

我目前回到 XCode 4.5,情况似乎好一点,但问题仍然存在。我想这个版本的功能比 4.6 少,根据这种差异,它使用的内存更少。

Ok, seems like XCode 4.5 actually CAN release some of memory that Interface Builder allocates.

好的,看起来 XCode 4.5 实际上可以释放 Interface Builder 分配的一些内存。

Update on May 21. 2013: I upgraded from 4GB to Mac Mini 2011 8GB RAM and did not notice problem yet.

2013 年 5 月 21 日更新:我从 4GB 升级到 Mac Mini 2011 8GB RAM 并且还没有发现问题。

回答by mas-designs

There's no real way around that problem.

没有解决这个问题的真正方法。

It's discussed on many websites. The only solution that helped me with this problem is, restarting XCode now an then. I don't think that there will be a real solution for this problem.

许多网站上都在讨论它。帮助我解决这个问题的唯一解决方案是,现在重新启动 XCode。我不认为这个问题会有真正的解决方案。

回答by SystematicFrank

XCode is a real memory monster, and if you trying using one of the "instruments" it eats even more. Depending on the tasks some people do not have that many issues, specially if they have more memory.

XCode 是一个真正的内存怪物,如果您尝试使用其中一种“工具”,它会吃得更多。根据任务的不同,有些人没有那么多问题,特别是如果他们有更多的记忆。

Personally I started with 2GB and XCode was just... painful

就我个人而言,我从 2GB 开始,而 XCode 只是……痛苦

After upgrading to 8GB I just had to restart every now and then

升级到 8GB 后,我只需要时不时地重新启动

I have heard that people with 16GB do not complain that much, and just have to restart XCode once or two a day.

我听说有 16GB 的人不会抱怨那么多,只需每天重新启动 XCode 一两次即可。

It looks quite strange to me that you use all your memory after 2 minutes. I might guess that there is some setting of yours that is making all XCode leaks much worst. Have you tried deleting all your ~/Library/Developer folder and setting files?

我觉得很奇怪,你在 2 分钟后用完了所有的记忆。我可能猜测您的某些设置使所有 XCode 泄漏变得更糟。您是否尝试删除所有 ~/Library/Developer 文件夹和设置文件?