from:http://www.cocoachina.com/bbs/read.php?tid=78426

这是Xcode4.2中的代码,不知strong什么意思?

#import <UIKit/UIKit.h>

@interface DataViewController : UIViewController
@property (strong, nonatomic) IBOutlet UILabel *dataLabel;
@property (strong, nonatomic) id dataObject;
@end

强引用与弱引用的广义区别:

  强引用也就是我们通常所讲的引用,其存亡直接决定了所指对象的存亡。如果不存在指向一个对象的引用,并且此对象不再显示列表中,则此对象会被从内存中释放。
  弱引用除了不决定对象的存亡外,其他与强引用相同。即使一个对象被持有无数个若引用,只要没有强引用指向他,那麽其还是会被清除。没办法,还是 “强哥” 有面子。

官方解释如下:

Automatic Reference Counting

Automatic Reference Counting (ARC) is a compiler-level feature that simplifies the process of managing the lifetimes of Objective-C objects. Instead of you having to remember when to retain or release an object, ARC evaluates the lifetime requirements of your objects and automatically inserts the appropriate method calls at compile time.


To be able to deliver these features, ARC imposes some restrictions—primarily enforcing some best practices and disallowing some other practices:

Do not call the retain, release, autorelease, or dealloc methods in your code.
In addition, you cannot implement custom retain or release methods.

Because you do not call the release method, there is often no need to implement a custom dealloc method—the compiler synthesizes all that is required to relinquish ownership of instance variables. You can provide a custom implementation of dealloc if you need to manage other resources.

Do not store object pointers in C structures.
Store object pointers in other objects instead of in structures.

Do not directly cast between object and nonobject types (for example, between id and void*).
You must use special functions or casts that tell the compiler about an object’s lifetime. You use these to cast between Objective-C objects and Core Foundation objects.

You cannot use NSAutoreleasePool objects.
Instead, you must use a new @autoreleasepool keyword to mark the start of an autorelease block. The contents of the block are enclosed by curly braces, as shown in the following example:

@autoreleasepool
{
   // Your code here
}
ARC encourages you to think in terms of object graphs, and the relationships between objects, rather than in terms of retain and release. For this reason, ARC introduces new lifetime qualifiers for objects, including zeroing weak references. The value of a zeroing weak reference is automatically set to nil if the object to which it points is deallocated. There are qualifiers for variables, and new weak and strong declared property attributes, as illustrated in the following examples:

// The following declaration is a synonym for: @property(retain) MyClass *myObject;
@property(strong) MyClass *myObject;

// The following declaration is similar to "@property(assign) MyOtherClass *delegate;"
// except that if the MyOtherClass instance is deallocated,
// the property value is set to nil instead of remaining as a dangling pointer
@property(weak) MyOtherClass *delegate;
Xcode provides migration tools to help convert existing projects to use ARC. For more information about how to perform this migration, see Xcode New Features User Guide. For more information about ARC itself, see Programming With ARC Release Notes.