泄漏是如何发生的?

发布于 2024-11-29 19:25:55 字数 339 浏览 0 评论 0原文

现在我已经了解了应用程序开发的关键部分,我正在检查是否存在挥之不去的内存泄漏。我决定尝试一下 Xcode 的 Leaks。当我第一次运行它时,它告诉我没有内存泄漏。欣喜了一分钟后,我仔细观察,查看了分配情况,意识到有几个对象漂浮在内存中,但我不希望它们在那里。例如,每次我创建一个 UIAlertView(这在我的应用程序中很常见)时,当它们从视图中消失时,我从来不会释放它们。这导致有几个 UIAlertView 对象浮动。

所以,我的问题是:Leaks 如何检测内存泄漏?当我有 UIAlertView 对象漂浮时,为什么不告诉我有任何泄漏?我只是错误地使用了Leaks吗?

So I've gotten to the nitty gritty part of my app development where I am going through checking for lingering memory leaks. I decided to give Xcode's Leaks a whirl. When I first ran it, it was telling me that I had no memory leaks. After a minute of rejoicing, I took a closer look, viewed the allocations and realized that I had several objects floating around in memory that I didnt want there. For instance, every time I created a UIAlertView (which was quite often in my app), I never release'd them when they were dismissed from the view. This led to having several UIAlertView objects floating around.

So, my question is: How does Leaks detect a memory leak? Why didn't tell me that there were any leaks when I had UIAlertView objects floating around? Am I just using Leaks wrong?

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

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

发布评论

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

评论(1

樱&纷飞 2024-12-06 19:25:55

如果您仍然有指向这些 UIAlertView 实例的指针,那么从技术上讲它们还不是泄漏。只有当您的应用程序无法再访问它们时,Leaks 工具才会将其视为泄漏。正如您所注意到的,确实有一些方法可以让您希望消失的东西仍然存在。这就是分配工具派上用场的地方。

If you still have pointers to those UIAlertView instances, they aren't technically a leak yet. Only when your app can't get to them anymore it is considered a leak by the Leaks instruments. As you noticed, there are indeed ways to have stuff still around that you would expect to be gone. That's where the Allocations instrument comes in handy.

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