开发者

iphone where are variables allocated in heap

I come from a microcontroller programming world, and I am learning to program on iOS,

I have a question that is being bothering me:

  • how to know the physical address of a the memory allocated t开发者_如何学JAVAo an object?

     NSString *nombre = [[NSString alloc] initWithString:@"nombreName"];
    

like the hexa address?? where to see this?

  • how big is the heap? can I see the heap at the beggining and after allocating to the objects?


Use gdb to inspect objects at runtime while debugging.

I've created a simple UIView object as,

UIView *someObject = [[UIView alloc] init];

and set a breakpoint on this line,

Stepping over this line so that someObject's memory is allocated, and then run po or print object on gdb shows the hex address of this object - 0x9304090.

(gdb) po someObject
<UIView: 0x9304090; frame = (0 0; 0 0); layer = <CALayer: 0x4b1b730>>

If the object's description method has been overridden, you may not see the hex address. For those objects, simply print the pointer

(gdb) p someObject
$2 = (UIView *) 0x9304090

or cast it to an int to see the memory location as a decimal.

(gdb) p (int) someObject
$3 = 154157200


You can use heapshots to look at status of heap and profile your application.

Example : http://useyourloaf.com/blog/2011/3/8/using-heapshots-to-find-abandoned-memory.html


The memory address of the object in your example would be "nombre". You can display it like this:

NSLog(@"nombre address is %x", nombre);

As for analyzing memory heap issues, you need look no further than XCode. Look under the run menu. There should be an entry called "run with performance tool". You should find everything you need there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜