ARC Rules

时间:2024-04-24 03:38:08

To write and compile source code for ARC, you have to take care of a few things. Just by following the rules in the list below, you can write source code for an ARC-enabled environment with confidence.

  • Forget about using retain, release, retainCount, and autorelease.

  • Forget about using NSAllocateObject and NSDeallocateObject.

  • Follow the naming rule for methods related to object creation.

  • Forget about calling dealloc explicitly.

  • Use @autoreleasepool instead of NSAutoreleasePool.

  • Forget about using Zone (NSZone).

  • Object type variables can’t be members of struct or union in C language.

  • ‘id’ and ‘void*’ have to be cast explicitly.

As described previously, the compiler doesn’t manage variables with the __unsafe_unretained ownership qualifier. You have to take care of ownership yourself to avoid a memory leak or the application will crash.

Conversely, __bridge_transfer cast will release the object just after the assignment is