简体   繁体   English

是否可以打印Objective-C,iOS变量的内存?

[英]Is it possible to print the memory of a Objective-C, iOS variable?

I want to know the memory of the variable taking up… Easily, i can calculate the address. 我想知道占用该变量的内存…轻松地,我可以计算地址。 Any convenient way to print the memory, for a NSArray, NSDictionary, and others. 对于NSArray,NSDictionary等,任何方便的打印内存的方式。

Any convenient way to print the memory, for a NSArray, NSDictionary, and others. 对于NSArray,NSDictionary等,任何方便的打印内存的方式。

The "memory" probably wouldn't tell you much. “记忆”可能不会告诉您太多。 Foundation's container classes store pointers to objects, so all you'd see is memory addresses. Foundation的容器类存储指向对象的指针,因此您所看到的只是内存地址。 Also, in order to understand "the memory" you'd need to know something about the internal structure of those classes. 另外,为了理解“内存”,您需要了解有关这些类的内部结构的一些知识。 In fact, different instances of those classes might not even have the same representation . 实际上,这些类的不同实例甚至可能没有相同的表示形式 Instead, you're far better off letting the object tell you what it contains. 相反,让对象告诉您它包含的内容要好得多。

You can use the -description method to get a description of most objects. 您可以使用-description方法来获取大多数对象的描述。 This is the usual way to inspect an object. 这是检查对象的常用方法。 There's also a -debugDescription , which is what the debugger calls to when you use the po command to print an object. 还有一个-debugDescription ,这是调试器在使用po命令打印对象时调用的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM