Xcode Instruments 使用大量内存。

发布于 2024-12-02 07:10:34 字数 360 浏览 1 评论 0原文

好的,这是我的问题,如果重复,我深表歉意。我进行了搜索,但找不到任何我认为相关的内容。

当我从 xcode 运行仪器并开始测试我的应用程序是否存在内存泄漏或分配时,我的 iMac 最终开始运行得非常非常慢。

这导致我在使用仪器时运行活动监视器,我注意到每打开第二个仪器就会占用越来越多的实际内存。每秒大约 100MB。

没过多久,它就耗尽了我所有 iMac 的可用内存(2GB),然后就开始滞后。

无论如何,并不是每个应用程序都会发生这种情况。我对我下载的一些应用程序/项目做了同样的测试,仪器似乎只使用了大约 250mbs 的空间,并且没有显着增加。

有什么明显的事情我做错了吗?任何帮助将不胜感激。

谢谢。

Okay so this is my issue and I apologize if its a duplicate. I searched but couldn't find anything I considered relevant.

When I run instruments from xcode and begin testing my application for memory leaks or allocations my iMac eventually begins to run very very slowly.

This caused me to run activity monitor while using instruments and I notice that every second instruments is open it takes up more and more real memory. Roughly 100MB's a sec.

It doesn't take long for it to consume all my iMacs free memory (2gbs) and then it starts to lag.

Anyways this doesn't occur with every application. I've done the same test with some application/projects I downloaded and instruments only seems to use about 250mbs of space and doesn't dramatically increase.

Is there something obvious that I'm doing incorrectly? Any help would be appreciated.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ˉ厌 2024-12-09 07:10:34

仪器消耗大量内存。

根据您录制的内容,您可以减少其内存使用量。例如,您通常可以指定要记录什么(或不记录什么),或降低采样频率(如果适用)。

100MB/s 是异常高的。你能更准确地描述一下你当时录制的内容吗? (您使用的仪器、您录制的过程正在做什么等)。

Xcode 3 使用的内存少得多 - 不确定 Instruments 是否也是如此。

您可以通过将工具集作为 32 位进程运行来稍微减少内存使用量。

最后,2GB 物理内存对于 Xcode + Instruments + iOS Sim 来说根本不算什么。 fwiw,我经常耗尽 8 GB 或更多 GB 的物理内存。嘘。幸运的是,当您想要 4 或 8GB 的​​内存时,内存很便宜。

更新

我尝试使用工具进行分配、泄漏和僵尸

如果必须的话,您可以单独运行这些测试。

分配

如果您的应用没有创建大量分配,则分配本身不应消耗大量内存。

要减少此工具的内存,您可以禁用一些您不感兴趣的选项:

  • 不记录每个引用计数操作
  • 仅跟踪活动分配
  • 禁用僵尸检测
  • 不识别 C++ 对象

泄漏

  • 意味着分配工具仅当您想要泄漏历史记录时

泄漏检测本身可能会消耗大量内存,因为它会扫描内存,基本上是克隆您的分配。假设您分配了 100MB - 泄漏将定期暂停进程、克隆内存并扫描其模式。这可能比您的应用程序消耗更多的内存。 iirc,它作为 Instruments 中的子进程执行。

僵尸

  • 意味着分配工具。

僵尸检测通常意味着引用计数记录。调试僵尸时,最有效的方法是永远不要释放它们。如果你释放它们,你可能只会检测到短暂的僵尸(不确定仪器中是否有选项......)。从不释放 objc 分配显然会消耗更多内存。在进程上运行泄漏将消耗更多内存,因为堆大小会更大 - 不应将泄漏和僵尸结合起来。

您应该能够通过禁用其中一些选项并单独测试它们来减少总消耗。

注释

  • 前沿的开发工具版本可能非常不稳定。如果您遇到问题,坚持使用官方版本会有所帮助。
  • 我可以仅使用分配来运行 osx 单元测试(主要是 c/c++ api),记录时消耗约 1MB/s。似乎有问题,但这可能表明您的程序存在问题(许多瞬态分配?)。
  • 更改数据显示方式和/或充电/聚焦设置可能需要大量内存。例如,“全部恢复”可能需要几 GB 来处理大样本。
  • 如果 100MB/s 是一个准确的数字,我会提交一个错误。我知道 Instruments 会消耗大量内存,但对于记录空闲应用程序来说,这非常高,即使预期 Instruments 会消耗大量内存。

祝你好运

instruments consumes a lot of memory.

depending on what you are recording, you may reduce its memory usage. for example, you can often specify what (or what not) to record, or lower sampling frequencies(if applicable).

100MB/s is unusually high. can you give a more exact description of what you are recording in that time? (instruments you use, what the process you record is doing, etc).

Xcode 3 used a lot less memory - not sure if that's also the case for Instruments.

You can reduce the memory usage somewhat by running the toolset as 32 bit processes.

lastly, 2GB physical memory is nothing for Xcode + Instruments + iOS Sim. fwiw, i regularly exhaust physical memory with 8 or more GB. boo. fortunately, memory is cheap when you want 4 or 8GB.

Update

I tried using instruments for Allocations, Leaks and Zombies

You can run these tests individually, if you must.

Allocations

By itself, allocations should not consume a ton of memory if your app is not creating a lot of allocations.

To reduce memory with this instrument, you can disable some options you are not interested in:

  • do not record each ref count operation
  • only track active allocs
  • disable zombie detection
  • do not identify c++ objects

Leaks

  • implies Allocations instrument only if you want history of leaks.

Leaks detection itself can consume a lot of memory because it scans memory, basically cloning your allocations. say you have 100MB allocated - leaks will periodically pause the process, clone the memory and scan it for patterns. this could consume more memory than your app. iirc, it's executed as a subprocess in instruments.

Zombies

  • implies Allocations instrument.

Zombie detection usually implies ref count recording. When debugging zombies, it's most effective to never free them. If you do free them, you may only detect transient zombies (not sure if there's an option for that in instruments...). Never freeing objc allocations will obviously consume more memory. Running leaks on a process will then consume more memory because your heap sizes will be larger - leaks and zombies should not be combined.

you should be able to reduce total consumption by disabling some of these options and testing for them individually.

Notes

  • The bleeding edge Developer Tools releases can be really shaky. If you are having problems, it helps to stick to the official releases.
  • I can run a osx unit test (primarily c/c++ apis) with allocations alone, it consumes about 1MB/s when recording. something seems wrong, but perhaps that indicates an issue in your program (many transient allocations?).
  • changing the way the data is displayed and/or the charge/focus settings can require a lot of memory. e.g. "Restore All" can require a few GB to process a large sample.
  • if 100MB/s is an accurate number, i'd file a bug. I know Instruments consumes a lot of memory, but that's very high for recording an idle app, even with the expectation that instruments consumes a lot of memory.

good luck

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文