本帖最后由 欧翔 于 2014-5-21 11:11 编辑
提问为什么对象里的NSString要用retain,字符串不是autorelease吗?
- #import <Foundation/Foundation.h>
- @interface User : NSObject
- @property (nonatomic, retain) NSString *name;
- @end
- #import "User.h"
- @implementation User
- -(void)dealloc{
- [_name release];
- NSLog(@"内存释放");
- [super dealloc];
- }
- @end
- #import <Foundation/Foundation.h>
- #import "User.h"
- int main(int argc, const char * argv[])
- {
- @autoreleasepool{
- User *p1 = [[User alloc] init];
- p1.name = @"sdadad";
- [p1 release];
- }
- return 0;
- }
复制代码 |
|