仪器中没有出现泄漏,尽管我确信它们存在

发布于 2024-07-26 11:13:17 字数 130 浏览 6 评论 0原文

我正在检查仪器是否有泄漏,并且我已设置每秒检查一次,但没有出现泄漏。

我确信我的应用程序中一定有一些,有什么可以阻止这些出现吗? 有没有一种好方法可以创建泄漏,以便我可以测试仪器中是否出现泄漏?

谢谢!

I'm checking for leaks in Instruments, and I've set to check every second, but no leaks are appearing.

I'm sure there must be some in my app, is there anything which could stop these from appearing? Is there a good way I can create a leak so that I can test if leaks do show up in Instruments?

Thanks!

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

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

发布评论

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

评论(3

半透明的墙 2024-08-02 11:13:17

创建泄漏很容易:

id someObject = [[NSObject alloc] init];
someObject = nil;

将一些类似的代码放入您的应用程序中,您肯定会在 Instruments 中看到泄漏。

Creating a leak is easy:

id someObject = [[NSObject alloc] init];
someObject = nil;

Drop some code like that into your app, and you should definitely see a leak show up in Instruments.

一身软味 2024-08-02 11:13:17

仅当对象已分配但不再被引用时,您才能使用工具发现泄漏。 另一种类型的“泄漏”是保留对您不想要的内容的引用。 这种情况通常发生在像哈希表或字典这样的集合中,其中键/值对留在程序员已经忘记的集合中。

You're only going to find leaks with a tool if an object is allocated but no longer referenced. Another type of "leak" is to hold a reference to something that you didn't intend to. This typically happens with a collection like a hash table or a dictionary where key/value pairs get left in the collection that the programmer has forgotten about.

养猫人 2024-08-02 11:13:17

我非常确定,正如 clemahieu 所假设的那样,您真正看到的是过度保留的对象 - 您认为您已经释放了它们,但它们仍然被保留。

对此的一种快速健全性检查是在 dealloc 中设置断点,并查看您希望释放的类是否确实存在。

您还可以使用内存跟踪工具(不是泄漏)来查看仍然存在哪些内存 - 只需确保选择“已创建且仍然存在”选项来检查仍然存在哪些对象。

I'm pretty sure as clemahieu postulated, what you are really seeing are over-retained objects - you think you have freed them but they still are being retained.

One quick sanity check for this is to set breakpoints in dealloc and see if the classes you expect to be freed really are.

You can also use the memory tracking Instrument (not leaks) to see what memory is still around - just make sure to select the "created and still living" option to check out just what what objects are still around.

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