discuss-gnustep
[Top][All Lists]
Advanced

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

Re: macros


From: David Relson
Subject: Re: macros
Date: Fri, 23 Feb 2001 09:36:59 -0500

At 07:33 PM 2/22/01, ian.mondragon@bankofamerica.com wrote:
all -

a message on the dev list reminded me of this long standing question of
mine:

why do so many people use the RELEASE(foo) and AUTORELEASE(foo) macros
instead of just typing out [foo release] or [foo autorelease] ?  they do the
same thing, but i just fail to see the logic in using the macro.

thanks.

Ian,

The macros have different definitions depending on the environment. I don't recall all the particulars, but I remember seeing one set of definitions for garbage collection and another set of autorelease pools.

While looking at the macros and their usage, I did notice an oddity: In approx 6 modules, both AUTORELEASE and RETAIN are used. For example in NSTimeZone.m, the following lines appear:

        zone = AUTORELEASE(RETAIN(defaultTimeZone));
        zone = AUTORELEASE(RETAIN(systemTimeZone));

These seem really odd. First, using both RETAIN and AUTORELEASE gives an expensive NOP - their effects cancel one another (in an involved, time-consuming manner). Second, with NextStep it was considered a mistake to call autorelease twice for the same object. Tracing through the code, I found 3 occurrences of the defaultTimeZone in the autorelease pool.

Looking in NSObject.h, unless the user has defined his/her own AUTORELEASE and RETAIN macros, the definitions will either be simple object references, i.e. AUTORELEASE(RETAIN(o)) is simply "o", or will be message sends of both retain and autorelease, i.e. "[[ o retain ] autorelease ]". I can see no reason for wanting this latter construct. Am I missing something? Should I submit patches to change the modules using AUTORELEASE(RETAIN(obj))?

David
--------------------------------------------------------
David Relson                   Osage Software Systems, Inc.
relson@osagesoftware.com       Ann Arbor, MI 48103
www.osagesoftware.com          tel:  734.821.8800




reply via email to

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