Re: ARC vs Manual Reference Counting
Re: ARC vs Manual Reference Counting
- Subject: Re: ARC vs Manual Reference Counting
- From: Dave <email@hidden>
- Date: Tue, 10 Sep 2013 19:07:43 +0100
Hi,
I think that's problem with it and a lot of other things too! Once you get out of the habit of thinking about memory management, you forget how to do it! How many people can do long multiplication or division on paper these days?? I started to do it the other day and had to really think to remember the rules!
The thing that bothers me about ARC is that it is a one-way street source code wise unless you put #ifdefs all over the place and then you invariably don't test the other version adequately. I try to make my code as compatible as possible, e.g for properties I still define a dealloc and set them to nil to release them. retain and release calls (for locals are harder to do right for both versions. If Apple had allowed the retain and release method calls as per Non-ARC but for ARC did nothing. This would at least allow code to be compiled for both versions.
For CF Objects I usually make them properties and then write getters and setters to manually CFRetain and CFRelease them.
The really good thing about ARC is that it does away with Auto-Release which is very good news IMO!
One thing that puzzles me is how ARC figures out how to handle something like this?
-(NSArray*) someMethod:(NSArray*) someArray andSomeValue:(NSInteger) someValue
{
NSArray * myArray;
if (someValue = 37)
myArray = [[NSArray alloc] init];
else
myArray = someArray;
return myArray;
}
Cheers
Dave
On 9 Sep 2013, at 08:44, Kyle Sluder <email@hidden> wrote:
> Thirded. I thought I wouldn't like it. As soon as I didn't have to manage retains and releases of temporary objects, the discipline completely left my mind. Now whenever I go back to non-ARC code I invariably make a ton of memory management errors, most of which are caught by the analyzer.
>
> --Kyle Sluder
>
> On Sep 8, 2013, at 11:18 PM, Alex Kac <email@hidden> wrote:
>
>> Bingo. We’ve been working with Cocoa/Obj-C for many years, and still we’d find weird errors that would be caused by some over-released object. We cut a ton of code with ARC, and in the end we saw reliability go up and actually even some performance.
>>
>> ARC is a win. The only place it really got a bit hairy was CF objects. I wish ARC would work with them a bit more.
>>
>> On September 8, 2013 at 11:56:10 PM, Jens Alfke (email@hidden) wrote:
>>
>> They’re a _lot_ easier. It might not look that way when you’re reading about all the details, or converting existing code, because then you’re focusing on the rare edge cases. But for the most part when actually coding you can simply ignore ref-counting. Your code becomes more compact and readable, and you’re less likely to make mistakes.
>> Alex Kac - President and Founder
>> Web Information Solutions, Inc.
>> _______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> 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:
>>
>> This email sent to email@hidden
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> 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:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden