1

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.

pkamb
  • 33,281
  • 23
  • 160
  • 191
seguedestination
  • 419
  • 4
  • 19
  • Check this: -[http://stackoverflow.com/questions/7555143/nslog-an-objects-memory-address-in-overridden-description-method](http://stackoverflow.com/questions/7555143/nslog-an-objects-memory-address-in-overridden-description-method) – Gandalf Jun 22 '15 at 02:24
  • The memory allocated for an `NSArray` or `NSDictionary` may not be contiguous so on some cases that would be difficult. – zaph Jun 22 '15 at 02:28

1 Answers1

2

Any convenient way to print the memory, for a NSArray, NSDictionary, and others.

The "memory" probably wouldn't tell you much. Foundation's container classes store pointers to objects, so all you'd see is memory addresses. 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. 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.

Community
  • 1
  • 1
Caleb
  • 124,013
  • 19
  • 183
  • 272