discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Which ObjC2.0 features are missing in the latest GCC?


From: H. Nikolaus Schaller
Subject: Re: Which ObjC2.0 features are missing in the latest GCC?
Date: Fri, 22 Nov 2019 11:51:40 +0100

> Am 22.11.2019 um 11:20 schrieb Andreas Fink <afink@list.fink.org>:
> 
> 
> 
>> On 22 Nov 2019, at 09:08, H. Nikolaus Schaller <hns@goldelico.com> wrote:
>> 
>> 
>>> Am 22.11.2019 um 08:40 schrieb David Chisnall <gnustep@theravensnest.org>:
>>> 
>>> On 22 Nov 2019, at 05:31, H. Nikolaus Schaller <hns@goldelico.com> wrote:
>>>> 
>>>> And the first thing I turn off in a
>>>> new Xcode project is ARC.
>>> 
>>> Why?  ARC generates smaller code, faster code, and code that is more likely 
>>> to be correct.
>> 
>> I never had a problem with any of those three. Code correctness is rarely a 
>> retain/release problem but the algorithm.
>> So it solves only a small percentage of the coding problems I do face.
> 
> 
> Then you have not done any big projects.

I have summed up wc -l on all of my *.m files and the sum is 1434555 in 5656 
files.
Not all are originally from me and there may be duplicates.

Doesn't seem to be big projects, indeed.

Still most coding problems are that the algorithm doesn't do what it should do 
(e.g. wrong loop counters, wrong break logic, wrong understanding of the 
requirements etc.).

> 
> Even though my code is well designed in terms of ownership of objects, I 
> still managed to every once in a while shoot myself into the foot and have to 
> track down memory leaks forever or random crashes.

Each time I have such a random crash the log tells me that a deallocated object 
is referenced and then it is usually easy to fix. But it rarely happens if you 
know the rules who owns the object and you do not randomly release something 
you don't own. Leaks are a little harder to detect but can also be avoided if 
ownership is well defined. Basic rule: you only (auto)release what you create 
(by alloc or copy) or what you store&retain to be used after ARP cleanup.

Sometimes it is also possible to set up unit tests checking -releaseCount.

> Switching to ARC made all these problems go away. No more use after free, no 
> more keeping objects around after no one uses it anymore etc.
> You don't have to think of releasing stuff if you are in the middle of a long 
> routine and throw an exception or call return.

Just use autorelease before risking the exception or return...

> This is a major advantage of Objc2.0. 
> I must admit it took me a while to get used to though. But at the end it paid 
> off a lot.

Well, to be precise: ARC could also be done with ObjC 1.0 as far as I see. 
There is IMHO no special syntax for ARC. You just remove all 
retain/release/autorelease from the code and the compiler is clever enough to 
magically make it still work.

So in summary, ARC alone isn't sufficiently helpful for my work to switch to 
ObjC 2.0 and no longer use gcc.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]