iPhone - 调试“未分配正在释放的指针” 错误

发布于 2024-07-08 15:55:34 字数 296 浏览 8 评论 0原文

当过度释放指针时,您可能会看到诸如

“被释放的指针未分配”

之类的错误在使用模拟器进行调试时,我添加了一个构建参数 MallocStackLogging = YES - 这允许我在终端中使用 malloc_history 来跟踪我的位置over 释放了一个指针。

如果我使用此构建参数在设备上进行调试,我会收到各种控制台错误“无法创建堆栈日志文件”等。

奇怪的是,我在设备上出现一些过度释放的指针错误,但在模拟器上却没有。

有人有过使用设备本身追踪这些的经验吗?

谢谢!

When over freeing a pointer you may see an error such as

"pointer being freed was not allocated"

When debugging with the simulator, I add a build argument MallocStackLogging = YES - this allows me to use malloc_history in the terminal to track down where I have over freed a pointer.

If I debug on the device with this build argument I get all sorts of console errors "cannot create stack log files" etc.

Oddly, I get some over freed pointer errors appearing on the device, but not on the simulator.

Has anyone had any experience tracking these down using the device itself?

Thanks!

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

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

发布评论

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

评论(4

仙气飘飘 2024-07-15 15:55:34

另一种方法可以做到这一点。 确保打开 NSZombie,以便它报告正在获得额外释放的对象的内存地址。 然后使用性能工具->对象分配运行。 这将调出仪器。 查看 Xcode 组织者提供的控制台日志。 一旦发生崩溃,查找仪器中的内存地址。 您将看到该对象上 malloc/free 的完整历史记录,以及直接指向您的代码的链接。

Another way to do this. Make sure to turn NSZombie on so it reports the memory address of the object that is getting the extra release. Then Run with Performance Tool->Object Allocations. This will bring up instruments. Look at the Console log as provided by Xcode organizer. Once you get the crash lookup the memory address in instruments. You will see the entire history of mallocs/frees on that object, as well as links straight into your code.

○愚か者の日 2024-07-15 15:55:34

我通常使用 NSZombie 来做这样的事情,检查这个

I generally use NSZombie for such things, check this out

樱花坊 2024-07-15 15:55:34

您需要在目标可执行文件上设置 MallocStackLogging 环境变量...

要访问这些设置,请从组和目录中选择您的可执行文件。 XCode 中的“文件”窗格,然后是“获取信息”。

转到“参数”选项卡,并将以下条目添加到“要在环境中设置的变量”框中:

You need to set the MallocStackLogging env variables on the target executable...

To access these settings, select your executable from the Groups & Files pane in XCode, then Get Info.

Go to the Arguments tab and add the following entries into the “Variables to be set in the environment” box:

新人笑 2024-07-15 15:55:34

请测试程序是否存在内存泄漏,同时检查自动释放以及是否正确释放对象。此外,我们还需要检查释放的对象是否分配了内存。您还需要小心自动释放,因为一不小心我们可能会释放一个数组或一个字符串或任何已经自动释放的对象...希望它有帮助并且有效!

提示:您可以通过分析项目来测试泄漏(点击shift+command+k)

Please test the program for memory leaks,Also check autoreleases and whether you are releasing objects properly or not.Also we need to check whether a released object has a memory allocated or not.You also need to be careful regarding autorelease,because accidentally we might release an array or a string or any object that is already autoreleased...hope it helps and works!

Tip: You can test for leaks by analyzing your project(click shift+command+k)

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