如何在调试时检查保留计数

发布于 2024-12-03 19:51:06 字数 164 浏览 2 评论 0原文

有谁知道如何在调试模式下检查对象的保留计数?我尝试添加表达式 [objInstance keepCount] 但它不起作用。我还在控制台中尝试了打印对象 PO [objInstance keepCount],但它再次不起作用。

Does anybody know how can I check the retain count of an object while in debug mode? I have tried to add an expression [objInstance retainCount] but it did not work. I have also tried the print object PO [objInstance retainCount] in the console but again it did not work.

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

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

发布评论

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

评论(2

忆悲凉 2024-12-10 19:51:06

我猜你正在谈论在GDB中获取retainCount

您可以使用retainCount方法。

这就是我进入代码的方式。

(gdb) p (int)[product retainCount]
$2 = 4

希望这就是您正在寻找的。

I am guessing you are talking about getting the retainCount in GDB?

You can use the retainCount method.

This is how I get in my Code.

(gdb) p (int)[product retainCount]
$2 = 4

Hope this is what you are looking for.

拥醉 2024-12-10 19:51:06

您可以使用以下命令打印此数字

NSLog(@"Retain count might be %d",[objInstance retainCount]);

。但是,由于 autorelease 等原因,该数字并不可靠。您应该阅读内存管理 并确保您的 retainrelease 调用匹配。您还可以运行“Build/Build”和“Analyze”来让 Xcode 帮助您找到可能的内存泄漏,但同样,这些只是潜在的泄漏。您需要亲自检查每一项才能确定。

You can print this with

NSLog(@"Retain count might be %d",[objInstance retainCount]);

However, this number isn't reliable due to things like autorelease. You should rather read up on memory management and make sure that your retain and release calls match up. You can also run Build/Build and Analyze to get Xcode to help you find possible memory leaks, but again, these are only potential leaks. You'll need to check each one yourself to be sure.

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