帮助查找内存泄漏(一般提示)
这是在 iOS 上,设备是 iPad。
发生的情况如下:
- 我在设备上运行应用程序或使用 Xcode 进行调试和运行。
- 5 分钟后,我收到 1 级内存警告。
- 一分钟后,我收到 2 级内存警告。
- 又一分钟后,
程序收到信号:“0”。
我使用 Leaks in 检查是否存在泄漏仪器未检测到泄漏。 然而,根据 Activity Monitor,我的应用程序最初使用 30 MB,并且随着时间的推移大小增长到超过 100mb(大约每秒 200kb!)。所以,显然 Leaks 并没有检测到所有内存泄漏。
所以我的问题是:如果 Leaks 无法检测到它,是否有任何通用提示来查找它们,以及是否有更好的工具来查找这些泄漏?
This is on iOS, device is iPad.
Here's what happens:
- I run app on device or debug and run using Xcode.
- After 5 minutes I receive a memory warning of level 1.
- A minute later I receive a memory warning of level 2.
- Another minute later,
Program received signal: “0”.
I checked for leaks using Leaks in Instruments and detected no leaks.
However, according to Activity Monitor, my app initially uses 30 MB, and grows in size to over 100mb over time (about 200kb per second!). So, apparently Leaks doesn't detect all memory leaks.
So my question: if Leaks can't detect it, are there any general tips to finding them, and is there a better tool to find these leaks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是我的处理方法,
用前缀命名所有类,以便您可以在仪器中轻松看到它们
XCode- >运行 -> 使用性能工具运行 -> 分配
现在停止你的应用程序并输入你怀疑正在泄漏的类的名称搜索框。 (这是前缀很方便的地方)。使用“记录”按钮再次启动仪器。
This is how I would approach it,
Name all you classes with a prefix so you can easily see them in Instruments
XCode->Run->Run with performance tool->allocations
Now stop your app and type the name of class you suspect is leaking in the search box. (this is where the prefix is handy). The start instruments again with the "Record" button
在你提到的情况下,并不一定存在泄漏。您可能在此处提到的执行时间点使用了大量自动释放的对象。
您可能要将大量对象添加到集合对象中。如果是这种情况,请针对这种情况使用单独的自动释放池,减少应用程序的内存占用。
It is always not necessary that you have leaks in the case you have mentioned. You might have used lot of autoreleased objects in the point of execution time that you mention here.
You might be adding a heavily sized objects to a collection object. If that is the case, use a separate Autorelease pool for that case, reduce the memory footprint of the application.
如果您可以使用工具来查找泄漏,那么这是首选,但如果完全陷入困境,我会使用另一种技术。
首先注释掉几乎所有内容,然后一次慢慢地添加回一个组件,直到再次发生内存泄漏。这样您就可以将导致问题的函数或代码块归零。
It's preferred if you can make use tools to find leaks, but if are completely stumped, there is another technique that I use.
Start with commenting out almost everything and then slowly add back one component at a time until the memory leak occurs again. That way you can zero in on the function or block of code that is creating the problem.