gpt4 book ai didi

objective-c - XCode 内存泄漏检测是如何工作的?

转载 作者:搜寻专家 更新时间:2023-10-30 20:08:01 24 4
gpt4 key购买 nike

XCode Instrument Leak 工具如何确定对象是泄漏还是只是尚未发布的对象?我是 Objective C 的新手,泄漏工具检测到我使用的代码中的泄漏。但是代码对我来说看起来很合理。所以只是想知道我能在多大程度上信任这个工具?

最佳答案

“泄漏”是一个仍在分配的对象,但您的应用程序不再具有引用指向那个对象。由于您不再有引用,因此您无法释放该对象,因此这是一个泄漏。

作为leaks(1) man page说:

leaks identifies leaked memory -- memory that the application has allocated, but has been lost and cannot be freed. Specifically, leaks examines a specified process's memory for values that may be pointers to malloc-allocated buffers. Any buffer reachable from a pointer in writable memory, a register, or on the stack is assumed to be memory in use. Any buffer reachable from a pointer in a reachable malloc-allocated buffer is also assumed to be in use. The buffers which are not reachable are leaks; the buffers could never be freed because no pointer exists in memory to the buffer, and thus free() could never be called for these buffers

您可能还想查看 Instruments 中的 ObjectAlloc 工具。

关于objective-c - XCode 内存泄漏检测是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2319908/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com