为什么我的 Cocoa 应用程序中的某些行需要永远运行?

发布于 2024-08-21 09:56:57 字数 203 浏览 8 评论 0原文

我有一个非常奇怪的问题。我正在一个分离的线程中运行一个循环,循环中的某些代码行(循环每次迭代中的不同行)需要很长时间(约 45 秒)才能执行,即使它们是简单的命令,例如使用数据初始化 NSXMLDocument。这个问题也很不一致,不会在同一个地方或者每次都出现。有什么想法为什么会发生这种情况吗?

附言。由于我的代码又长又复杂,而且问题不一致,所以我无法发布任何示例代码:/

I'm having a very strange problem. I'm running a loop in a detached thread, and some lines of code in my loop (different lines in each iteration of the loop) are taking a long long time (~45 seconds) to execute, even if they are simple commands like initializing an NSXMLDocument with data. This problem is also very inconsistent, and it doesn't occur in the same place or each time. Any ideas why this is happening?

PS. Since my code is so long and complex, and the problem isn't consistent, I can't post any sample code :/

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

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

发布评论

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

评论(3

一花一树开 2024-08-28 09:56:57

不要猜测性能问题。有很多工具可以帮助您确定问题所在,包括 Instruments 应用程序和 Shark< /a>.这两者都可以让您准确分析 CPU 时间的去向,以便您可以采取一些措施。

Don't guess about performance issues. There are plenty of tools to help you determine what is going wrong, including the CPU Sampler instrument in the Instruments app, and Shark. Both of these will let you analyse exactly where the CPU time is going, so you can do something about it.

無處可尋 2024-08-28 09:56:57

使用工具找出原因。

Use Instruments to find out why.

凶凌 2024-08-28 09:56:57

别人怎么说;您应该使用 Instruments 来确定时间都去哪儿了。特别是,您需要使用 CPU 采样器工具和虚拟内存活动工具。

从声音来看,我敢打赌您的应用程序正在导致系统耗尽 RAM 并开始分页到磁盘。这将按照您所描述的方式消除杀伤性能;在运行过程中的某个不确定的时间,应用程序似乎要么超级缓慢,要么只是暂停了一段时间。

您可能还应该使用对象分配工具来确定您是否按预期使用内存,如果使用相当多,您可以在哪里优化内存使用。

What others said; you should use Instruments to identify where the time is going. In particular, you'll want to use the CPU sampler instrument and the virtual memory activity instrument.

From the sounds of it, I would bet that your application is causing the system to run out of RAM and start paging to disk. This will flat out kill performance in exactly the way you describe; at some indeterminate time during the run, it seems like the app is either super sluggish or just pauses for a while.

You should probably also use the Object Alloc instrument to figure out if you are using memory as expected and, if using quite a lot, where you might optimize your memory use.

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