Objective-C >> 获取内存中的对象地址

标签 objective-c memory-management memory-address

如何在我的代码中的某个点捕获对象的地址? 例如:

NSString * aString = @"bla bla";
//what is the current address of aString. i.e to which address in memory does it currently point to
aString = @"la la la";
//what is the current address of aString.

最佳答案

示例:

NSString *temp = @"123";

uintptr_t ptrAddress = (uintptr_t) temp;

NSLog(@"%@ %p %lu", temp, temp, ptrAddress);

控制台:

2013-07-11 11:51:20.796 asd[6474:907] 123 0x17985c 1546332

它也可能对您有用 - NSPointerArray (iOS 6+)

关于Objective-C >> 获取内存中的对象地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17588679/

相关文章:

objective-c - Objective-c 中的消息是什么?

c++ - Ifstream 因未知原因失败

c - 我们为什么需要存储分配?

c - 如何在 32 位地址空间内分配缓冲区?

iphone - 5.0 Base SDK 应用无法安装在 5.1 操作系统的 iPad 上

objective-c - PDFAnnotationText 在 10.12 上不显示弹出窗口

delphi - FastMM:分配的总内存

c - 释放对象错误

java - 技嘉 vs 吉比 & 技嘉 vs 吉比

iOS9 - 分享到 Instagram(w/hooks)不工作