3

what does RELEASE_SAFELY or RELEASE_CF_SAFELY mean? Ok, it's for releasing objects but why not use [obj release]?

Besides I tried to use it in xcode 4 but I am running into buid errors:

Undefined symbols for architecture i386:
  "_RELEASE_SAFELY", referenced from:
      -[AdressBookModel search:] in AdressBookModel.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status

Can I do just [obj release] instead? What would you consider?

DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601

1 Answers1

4

RELEASE_SAFELY is not a function but a macro and is usually defined like this:

#define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }

(I think it's not part of the SDK but has to be declared in each project separately. And I don't think it has anything to do with the XCode version.)

So it first calls release and then additionally sets the variable to nil. That's good practice because it prevents double releases or access to a deallocated instance.

It seems that your code believes it's a function (instead of a macro). Probably the compiler warns you that it hasn't been declared.

The fix is to put the above macro definition in an appropriate header file.

Codo
  • 75,595
  • 17
  • 168
  • 206