0
我想弄明白,为什么下面的代码导致泄漏。所以我有以下自定义init方法:在初始化调试内存泄漏
@property (nonatomic, retain) NSString *userId;
@property (nonatomic, retain) NSString *text;
@property (nonatomic, retain) NSString *username;
@property (nonatomic, retain) NSString *creatorName;
@property (nonatomic, retain) NSString *profilePicture;
@property (nonatomic, retain) NSString *imageId;
@property (nonatomic, retain) NSString *imageLink;
@property (nonatomic, retain) NSString *createdTime;
@property (nonatomic, retain) NSMutableArray * imageLikes;
@property (nonatomic, retain) NSMutableArray * imageComments;
@property (nonatomic, retain) NSDictionary *image;
@property (nonatomic, assign) int commentsCount;
@property (nonatomic, assign) int likesCount;
@property (nonatomic, assign) int index;
@property (nonatomic, assign) int numberOfRows;
@property (nonatomic, assign) BOOL increaseHeight;
@property (nonatomic, assign) BOOL userHasLiked;
@property (nonatomic, assign) BOOL canResetHeight;
-(id)initWithData:(NSDictionary *)data
{
self = [super init];
if (!self) {
return nil;
}
self.text = [[data valueForKey:@"caption"] valueForKey:@"text"];
self.createdTime = [[data valueForKey:@"caption"] valueForKey:@"created_time"];
self.imageId = [data valueForKey:@"id"];
self.imageLink = [data valueForKey:@"link"];
NSDictionary *from = [data valueForKey:@"user"];
self.username = [from valueForKey:@"username"];
self.profilePicture = [from valueForKey:@"profile_picture"];
self.creatorName = [from valueForKey:@"full_name"];
self.userId = [from valueForKey:@"id"];
self.userHasLiked = [[data objectForKey:@"user_has_liked"] boolValue];
self.commentsCount = [[[data valueForKey:@"comments"] valueForKey:@"count"] intValue];
self.likesCount = [[[data valueForKey:@"likes"] valueForKey:@"count"] intValue];
self.image = [data valueForKey:@"images"];
self.increaseHeight = NO;
self.numberOfRows = -1;
return self;
}
-(void) dealloc
{
[createdTime_ release];
[imageLink_ release];
[imageId_ release];
[imageLikes_ release];
[imageComments_ release];
[username_ release];
[userId_ release];
[profilePicture_ release];
[text_ release];
[creatorName_ release];
[super dealloc];
}
任何想法为什么?
+1对你来说比我快......另外,对于@adit,[你应该不使用init和dealloc方法中的属性访问器](http:// stackoverflow。 COM /问题/ 192721 /为什么 - 不应该,我使用的目标-C-2-0-存取功能于INIT-的dealloc)。 – 2012-07-26 04:23:16
@MichaelDautermann任何解释为什么? – adit 2012-07-26 04:44:24
点击我在评论中包含的链接。 – 2012-07-26 04:45:22