如何检测未正确发布的内容

发布于 2024-11-28 15:59:17 字数 111 浏览 1 评论 0原文

为iphone 编写一个程序。意识到我忘记释放一个对象,但实际上没有任何迹象表明该对象没有被释放,一切都正常。

追踪此类事件的最佳方法是什么?有没有办法在程序退出时查看内存中仍然存在哪些对象?

Writing a program for the iphone. Realized that I forgot to release an object, but there was really no indication that the object was not released everything just worked.

What is the best way to track something like this down? Is there a way to see what objects still exist in memory when the program exits out?

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

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

发布评论

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

评论(5

别想她 2024-12-05 15:59:17

严格来说,当程序退出时,内存中剩下的内容并不重要:系统会释放应用程序在其生命周期中分配的所有内容。不过,从 iOS 4 开始,应用程序通常会冻结在后台,直到系统杀死它们以释放内存后才会退出。为了避免这种情况,并减少应用程序的内存占用(这在应用程序运行时很重要),您应该按照高度咖啡因和 Daniel 的建议,使用 Instruments 的 Leaks 工具来检查未正确释放的对象。

Strictly speaking, when the program exits, it doesn’t matter what you’ve left in memory: the system frees everything that your application allocated throughout its lifetime. Since iOS 4, though, apps usually just get frozen in the background and don’t exit until the system kills them to free up memory. To avoid that—and to reduce your app’s memory footprint, which is important while it’s running—you should, as highlycaffeinated and Daniel suggested, use Instruments’s Leaks tool to check for objects that aren’t getting deallocated properly.

桃扇骨 2024-12-05 15:59:17

当应用程序退出时,内存中的所有内容都会被系统销毁(不会释放,而是在将地址空间返还给系统时彻底销毁)。

虽然其他人建议使用 Leaks 工具来查找应用程序中的泄漏,但 Leaks 不会发现多种类型的内存增长。如果一个对象被分配,被推到缓存中的某个地方,那么缓存中该对象的键就会丢失,该对象实际上被泄漏(永远不能再次使用),但不会被泄漏找到,因为它仍然连接到你的可行的对象图。

更好的选择是使用 Heapshot 分析来查看应用程序的对象图如何随时间增长。我写了一个 使用 Heapshot 分析的教程,您可能会觉得有用。

如果您想在应用程序退出之前获取快照,请将 sleep(1000); 放入应用程序终止处理程序或应用程序退出之前执行的其他位置的代码中。

请记住在交付生产版本之前将其删除。 :)

When the app exits, anything in memory is destroyed by the system (not deallocated-- but just outright destroyed when the address space is given back to the system).

While others have suggested using the Leaks tool to find leaks in your app, Leaks won't find many many kinds of memory accretion. If an object is allocated, shoved in a cache somewhere, then the key to that object in the cache is lost, the object is effectively leaked (can never be used again) but won't be find by Leaks because it is still connected to your viable object graph.

A better bet is to use Heapshot analysis to see how your app's object graph grows over time. I wrote up a tutorial on using Heapshot analysis that you might find useful.

If you want to grab a snapshot just before your app exits, then put a sleep(1000); into your code in either an application termination handler or somewhere else that is executed just before the app exits.

Just remember to remove it before shipping a production build. :)

一曲琵琶半遮面シ 2024-12-05 15:59:17

一旦应用程序退出 - 您将无法访问该应用程序。但 Instruments(一个 XCode 工具)可以查找内存泄漏。

Once an application quits - you don't have access to that. But Instruments (an XCode tool) can look for memory leaks.

梦境 2024-12-05 15:59:17

当 pprogram 退出时,内存中不存在任何内容。但是您可以从分析代码(产品 -> 分析)开始,并使用(产品 -> 配置文件)仪器中的分配或泄漏来运行它,以查找内存管理问题。

Nothing exists in memory when pprogram exits. But you can start with analyzing your code (Product -> Analyze) and running it with (Product -> Profile) Allocations or Leaks in Instruments to find memory management issues.

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