discuss-gnustep
[Top][All Lists]
Advanced

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

Re: Cocoa/GNUStep compatible build


From: Ivan Vučica
Subject: Re: Cocoa/GNUStep compatible build
Date: Tue, 11 Sep 2012 16:01:08 +0200

On Tue, Sep 11, 2012 at 2:56 PM, pepijn de vos <pepijndevos@yahoo.com> wrote:
You hand written setter is tricky though. Most people seem to be using autorelease? I wonder what the actual synthesised methods look like.

As David suggested, you can look into the runtime. People may use autorelease, but as I said, this means that (depending on how often a setter using autorelease is used) you may be adding a lot, lot, lot objects to the autorelease pool. This means a lot of potentially temporary objects that you may have released immediately after temporarily setting them into an object would wound up staying around until next -drain/-release of the autorelease pool.


What happens when you have no autorelease pool? I was hoping it would crash, and tell me what happened, but I assume I'm just leaking memory now.

Yes, you're leaking memory.


On Tue, Sep 11, 2012 at 3:01 PM, David Chisnall <theraven@sucs.org> wrote:
On 11 Sep 2012, at 13:56, pepijn de vos wrote:

> I dropped ARC for now. I found that with autorelease pools an getters and setters, refcounting is not that painful at all.

Hmm, I forgot to hit reply-all on my post suggesting that you don't do this.  With ARC, you must think about object ownership, with manual retain/release you must think about reference counting, which is less obvious.  Oh, and you get slower and buggier code in return for putting in this extra effort.

Without going much deeper into the subject once again, I respectfully disagree with David here. It has to do with people staying aware of the underlying mechanisms. Not treating things as "magical" seems important for good engineering on part of newcomers to a language. And while ARC may not make Objective-C a garbage-collected language as 10.5-era addition of GC did, it comes very close.

In short: it's good to teach people that ObjC objects are pointers to structures that contain a pointer to a class-describing structure; it's good to teach people that nibs are not magically unpacked, but are decodable archives; it's good to teach people objects are not magically packed when saving an archive such as a nib, but that objects contain a special method that knows what data must be added into the stream; it's good to teach people that there are conventions. And finally - it's good to teach people that there is something called "reference counting", and drill that into their head by forcible repetition (repeated typing of words "retain", "release", "autorelease" in appropriate places does help!), so they can later appreciate the "magic" of ARC or spot problems that ARC might cause. And let's not forget that a person will more easily understand the concept of cyclic reference this way.

To wrap up this extended rant, I definitely disagree with the distinction between thinking about reference counting and object ownership. Particularly since the concepts of (manual) reference counting are explained, in multiple sources, through and using the concept of object ownership. :-)
--
Ivan Vučica - ivan@vucica.net



reply via email to

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