When working with the Boehm's garbage collector, the messages used by
the reference counting mechanism are obsolete and they simply introduce
an unnecessary overhead. That's why instead of sending the
retain, release and autorelease messages you'd
better use the macros with the similar names, RETAIN,
RELEASE and AUTORELEASE. When the code is compiled with
support for Boehm's garbage collector the correspondent messages are not
sent at all.
In addition to the above macros, another macro should be used to make
the code cleaner. The ASSIGN macro can be used whenever an object
value is assigned to an object variable and the old value of the
variable needs to be release and the new value retained. The definition
of this macro is:
#define ASSIGN(object, value) \
({if (value) [value retain]; \
if (object) [object release]; \
object = value;})
When Boehm's garbage collector is used the definition of the macro is simply:
#define ASSIGN(object, value) \ object = value
Another macro can be used whenever the code requires the creation of an
autorelease pool. This pool is not needed when the code works in the
presence of Boehm's garbage collector. The macro is
CREATE_AUTORELEASE_POOL and should be used as a variable
definition and must placed the last in the variables definition
list. Use the RELEASE macro to release the pool.
The preprocessor define LIB_FOUNDATION_BOEHM_GC can be used to
find out if the program is compiled with support for Boehm's garbage
collector (See section Preprocessor defines for other preprocessor
defines). If you need to find out at runtime if the program was compiled
with support for Boehm's collector you can access the read-only variable
_usesBoehmGC.
Go to the first, previous, next, last section, table of contents.