Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C class instance zeroed at alloc?

Is there any kind of memory-zeroing objective-c undertakes on my behalf when I first allocate a class instance? I see a lot of objective-c code out there that presumes their outlets are nil by default. If I do the same am I basing such behavior on false pretenses?

like image 439
fbrereto Avatar asked Dec 06 '22 05:12

fbrereto


1 Answers

NSAllocateObject returns a block of memory large enough to include all the ivars in the class; its isa pointer is set to the class, and the rest of the block is filled with 0. +[NSObject alloc] calls +[NSObject allocWithZone:] which then calls NSAllocateObject internally.

like image 179
rpetrich Avatar answered Dec 11 '22 15:12

rpetrich