[[NSDate date] retain]和[[NSDate alloc] init]之间的差异 [英] Difference between [[NSDate date] retain] and [[NSDate alloc] init]
问题描述
由于以下两个目的相同,
today = [[NSDate date] retain];
和
c $ c> today = [[NSDate alloc] init];
那么它们之间有什么区别?
这里的任何内容都与内存有关
[NSDate date]
是一个方便的构造函数,使用它可以离开将对象释放到autorelease pool的头痛。向 [[NSDate date] retain]
的方便构造函数发送保留
消息使您成为对象的所有者,
[[NSDate alloc] init]
是默认的初始化方法,成为该对象的所有者,几乎等于 c。[[NSDate date] retain] 。
As both of the following serves the same purpose,
today = [[NSDate date] retain];
and
today = [[NSDate alloc] init];
Then what's the difference between them?
Does anything here is related to memory allocation methods or something else is the reason for using them accordingly.
[NSDate date]
is a convenience constructor using which you can leave the headache of releasing the object to autorelease pool. Sending a retain
message to the convenience constructor like [[NSDate date] retain]
makes you the owner of the object and you are responsible for releasing it properly.
[[NSDate alloc] init]
is the default initializer by which you become the owner of the object, which is almost equal to [[NSDate date] retain]
.
这篇关于[[NSDate date] retain]和[[NSDate alloc] init]之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!