仪器中没有出现泄漏,尽管我确信它们存在
我正在检查仪器是否有泄漏,并且我已设置每秒检查一次,但没有出现泄漏。
我确信我的应用程序中一定有一些,有什么可以阻止这些出现吗? 有没有一种好方法可以创建泄漏,以便我可以测试仪器中是否出现泄漏?
谢谢!
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
创建泄漏很容易:
将一些类似的代码放入您的应用程序中,您肯定会在 Instruments 中看到泄漏。
Creating a leak is easy:
Drop some code like that into your app, and you should definitely see a leak show up in Instruments.
仅当对象已分配但不再被引用时,您才能使用工具发现泄漏。 另一种类型的“泄漏”是保留对您不想要的内容的引用。 这种情况通常发生在像哈希表或字典这样的集合中,其中键/值对留在程序员已经忘记的集合中。
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.
我非常确定,正如 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.