Re: ARC and Manual Memory Management
Re: ARC and Manual Memory Management
- Subject: Re: ARC and Manual Memory Management
- From: Dave <email@hidden>
- Date: Mon, 10 Aug 2015 16:35:44 +0100
> On 10 Aug 2015, at 13:21, Roland King <email@hidden> wrote:
>
>
>> On 10 Aug 2015, at 19:59, Dave <email@hidden <mailto:email@hidden>> wrote:
>>
>> Hi,
>>
>> Has anyone come up with a way of having the source code support both ARC and Manual Memory Management without using #IFDEF or #IF ?
>>
>> I’ve never understood why the compiler doesn’t just ignore code like:
>>
>> [super dealloc];
>>
>> [MyObj release];
>>
>> If it’s being compiled for ARC, that way both could be compiled with the same source code or is there more to it?
>>
>>
>
> What’s the use case here? ARC and MMR are completely interoperable. When would you need to compile a file under both? If it’s legacy and needs to build under a really old compiler then you don’t convert it to ARC and you always compile it non-ARC, once it’s converted you always compile it with ARC no matter what you’re doing for other files in the project.
>
> As for why - the rationale is in section 7.1.1 of the arc spec http://clang.llvm.org/docs/AutomaticReferenceCounting.html <http://clang.llvm.org/docs/AutomaticReferenceCounting.html> and the following section for dealloc. It’s specified that code is ill-formed if it includes any of those and so the compiler has to follow the spec to it can’t ignore them. You may or may not agree with the rationale, but at least the specifiers of the language did write down why it’s that way.
That’s fair enough, I was wondering if there was any deep reason. The thing is I have library classes that I use in older projects that are non-ARC, I was trying avoid having two sets of more or less identical files.
I preprocessor that removes them if the project is ARC might work, but I guess it would probably confuse the debugger.
I saw it done horribly once, where instead of calling [super dealloc]; it used [super Dealloc]; and [myObject Release]; and then defined these methods as a category on NSObject. I really don’t fancy doing that.
Cheers
Dave
_______________________________________________
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