- You cannot explicitly invoke dealloc, or implement or invoke retain, release, retainCount, or autorelease.
The prohibition extends tousing @selector(retain), @selector(release), and so on.
You may implement a dealloc method if you need to manage resources other than releasing instance variables. You donot have to (indeed you cannot) releaseinstancevariables, but you may need to invoke [systemClassInstance setDelegate:nil] onsystem classes and other code that isn’t compiledusing ARC.
Custom dealloc methods in ARC donot require a callto [super dealloc] (it actually results in a compiler error). The chaining to super is automated andenforcedby the compiler.
You can still use CFRetain, CFRelease, and other related functions with Core Foundation-style objects (see Managing Toll-Free Bridging).
- You cannot use NSAllocateObject or NSDeallocateObject.
You create objects using alloc; the runtime takes care of deallocating objects.
- You cannot useobject pointers in C structures.
Rather thanusing a struct, you can create an Objective-C classto manage the data instead.
- There isno casual casting betweenidandvoid *.
You must use special casts that tell the compiler about object lifetime. You need todo this tocastbetween Objective-C objects and Core Foundation types that you pass asfunction arguments. For more details, see Managing Toll-Free Bridging.
- You cannot use NSAutoreleasePool objects.
ARC provides @autoreleasepool blocks instead. These have an advantage of being more efficient than NSAutoreleasePool.
- You cannot usememory zones.
There isno need touse NSZone any more—they are ignored by the modern Objective-C runtime anyway.
- You cannot give an accessor a name that begins with new. This in turn means that you can’t, for example, declare a property whose name begins withnew unless you specify a different getter:
__strong isthe default. An object remains “alive” as long as there is a strong pointer toit.
__weak specifies a referencethatdoesnot keep the referenced object alive. A weak referenceissetto nil when there are no strong references tothe object.
__unsafe_unretained specifies a referencethatdoesnot keep the referenced object alive andisnotsetto nil when there are no strong references tothe object. If the object it references is deallocated, the pointer is left dangling.
__autoreleasing is used to denote arguments that are passed byreference (id *) and are autoreleased onreturn.
所有权修饰符的规范写法:ClassName * qualifier variableName;
outlets 应该使用 weak,官方解释:
1
2
3
outlets should be weak, except for those from File’s Owner to top-level objects ina nib file (ora storyboard scene) which should be strong.
Full details are given in Nib Files in Resource Programming Guide.