Objective-C类实例在alloc处归零? [英] Objective-C class instance zeroed at alloc?
问题描述
当我第一次分配一个类实例时,是否有任何类型的内存清零目标-c代表我进行?我看到很多Objective-c代码默认情况下假设它们的出口是 nil
。如果我这样做,我会基于虚假借口进行此类行为吗?
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?
推荐答案
NSAllocateObject
返回一个足够大的内存块,以包含类中的所有ivars;其 isa
指针设置为该类,其余部分填充为0. + [NSObject alloc]
调用 + [NSObject allocWithZone:]
然后在内部调用 NSAllocateObject
。
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.
这篇关于Objective-C类实例在alloc处归零?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!