Re: Resend: array = [NSArray new] or array = [NSArray array]?
To all who replied, thank you. This is awesome. Thanks for outlining the difference between the two. Now I know and can ignore it. But if I didn't, I'd always be wondering. This certainly puts my mind at ease. Well, at least with regards to [NSArray new]. Other issues shall remain uneased for the moment. Cheers. - Alex Zavatone On Aug 19, 2016, at 12:59 PM, Gary L. Wade wrote: > The class method new is the same as alloc/init although by implementation, it > may be faster if the class doesn't need to pass a placeholder object from > alloc—some classes do that. The class method array is much like > alloc/init/autorelease in the MRC days although it may coalesce things, but > that's an implementation detail you as a user shouldn't be too concerned > about. > > The biggest cause for concern is if you're writing this code in MRC vs ARC > since you'd have to manage these memory points yourself. > -- > Gary L. Wade (Sent from my iPhone) > http://www.garywade.com/ > >> On Aug 16, 2016, at 7:42 AM, Alex Zavatonewrote: >> >> I sent this out this morning but it got eaten, so this is a resend. Sorry >> if it gets to some of you twice. >> >> >> >> Yes, I know about literals, but I have a different question here. >> >> >> Is this safe? >> >> I have seen this in some code in our codebase: >> array = [NSArray new]; >> >> I'm familiar with using the public method from the NSArray header and what >> the docs say to use: >> or array = [NSArray array]; >> >> Is there any risk to using [NSArray new] to init an array instead of >> [NSArray array]?? >> >> I'm surprised to see this being used in our codebase and would like to make >> sure we are not destroying the universe by using it. >> >> Thank you in advance. >> - Alex Zavatone >> > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Resend: array = [NSArray new] or array = [NSArray array]?
The class method new is the same as alloc/init although by implementation, it may be faster if the class doesn't need to pass a placeholder object from alloc—some classes do that. The class method array is much like alloc/init/autorelease in the MRC days although it may coalesce things, but that's an implementation detail you as a user shouldn't be too concerned about. The biggest cause for concern is if you're writing this code in MRC vs ARC since you'd have to manage these memory points yourself. -- Gary L. Wade (Sent from my iPhone) http://www.garywade.com/ > On Aug 16, 2016, at 7:42 AM, Alex Zavatonewrote: > > I sent this out this morning but it got eaten, so this is a resend. Sorry if > it gets to some of you twice. > > > > Yes, I know about literals, but I have a different question here. > > > Is this safe? > > I have seen this in some code in our codebase: > array = [NSArray new]; > > I'm familiar with using the public method from the NSArray header and what > the docs say to use: > or array = [NSArray array]; > > Is there any risk to using [NSArray new] to init an array instead of [NSArray > array]?? > > I'm surprised to see this being used in our codebase and would like to make > sure we are not destroying the universe by using it. > > Thank you in advance. > - Alex Zavatone > ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Resend: array = [NSArray new] or array = [NSArray array]?
+new is alloc/init. +array is alloc/init/autorelease. Should be equivalent. > On Aug 16, 2016, at 7:42 AM, Alex Zavatonewrote: > > I sent this out this morning but it got eaten, so this is a resend. Sorry if > it gets to some of you twice. > > > > Yes, I know about literals, but I have a different question here. > > > Is this safe? > > I have seen this in some code in our codebase: > array = [NSArray new]; > > I'm familiar with using the public method from the NSArray header and what > the docs say to use: > or array = [NSArray array]; > > Is there any risk to using [NSArray new] to init an array instead of [NSArray > array]?? > > I'm surprised to see this being used in our codebase and would like to make > sure we are not destroying the universe by using it. > > Thank you in advance. > - Alex Zavatone > > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com > > This email sent to david.dun...@apple.com -- David Duncan ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Resend: array = [NSArray new] or array = [NSArray array]?
> On Aug 16, 2016, at 9:42 AM, Alex Zavatonewrote: > > I sent this out this morning but it got eaten, so this is a resend. Sorry if > it gets to some of you twice. > > > > Yes, I know about literals, but I have a different question here. > > > Is this safe? > > I have seen this in some code in our codebase: > array = [NSArray new]; > > I'm familiar with using the public method from the NSArray header and what > the docs say to use: > or array = [NSArray array]; > > Is there any risk to using [NSArray new] to init an array instead of [NSArray > array]?? > > I'm surprised to see this being used in our codebase and would like to make > sure we are not destroying the universe by using it. They’re both perfectly fine. [NSArray new] is just a synonym for [[NSArray alloc] init], whereas [NSArray array] is a synonym for [[[NSArray alloc] init] autorelease]. In ARC, I actually prefer +new, as there’s no difference UI-wise, and it keeps the array out of the autorelease pool. Charles ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: Resend: array = [NSArray new] or array = [NSArray array]?
Under ARC there should be no appreciable difference. People who prefer +new will generally point out it's a keyword or operator in other languages so its meaning is not ambiguous. With manual reference counting, the difference is that +array is autorelease where as with +new your code is responsible for releasing the object. Some projects used to discourage the use of +new as it was one less selector/function name to memorize (i.e. copy, alloc, create..., new). On Tue, Aug 16, 2016 at 7:42 AM, Alex Zavatonewrote: > I sent this out this morning but it got eaten, so this is a resend. Sorry > if it gets to some of you twice. > > > > Yes, I know about literals, but I have a different question here. > > > Is this safe? > > I have seen this in some code in our codebase: > array = [NSArray new]; > > I'm familiar with using the public method from the NSArray header and what > the docs say to use: > or array = [NSArray array]; > > Is there any risk to using [NSArray new] to init an array instead of > [NSArray array]?? > > I'm surprised to see this being used in our codebase and would like to > make sure we are not destroying the universe by using it. > > Thank you in advance. > - Alex Zavatone > > > ___ > > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) > > Please do not post admin requests or moderator comments to the list. > Contact the moderators at cocoa-dev-admins(at)lists.apple.com > > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/cocoa-dev/ > conceptuallyflawed%40gmail.com > > This email sent to conceptuallyfla...@gmail.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Resend: array = [NSArray new] or array = [NSArray array]?
I sent this out this morning but it got eaten, so this is a resend. Sorry if it gets to some of you twice. Yes, I know about literals, but I have a different question here. Is this safe? I have seen this in some code in our codebase: array = [NSArray new]; I'm familiar with using the public method from the NSArray header and what the docs say to use: or array = [NSArray array]; Is there any risk to using [NSArray new] to init an array instead of [NSArray array]?? I'm surprised to see this being used in our codebase and would like to make sure we are not destroying the universe by using it. Thank you in advance. - Alex Zavatone ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com