Objective-C类实例在alloc处归零? [英] Objective-C class instance zeroed at alloc?

查看:129
本文介绍了Objective-C类实例在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆