When i run profile with this code in Instruments, I got 35 memory leaks of Player. How i need to handle to avoid memory leaks?
NSMutableArray *players = [NSMutableArray array];
NSData *data = [theRequest responseData];
NSArray *array = (NSArray *) [decoder objectWithData:data];
int len = 35;
for (int i = 0; i < len; i++) {
NSDictionary *dic = (NSDictionary *) [array objectAtIndex:i];
Player *p = [[Player alloc] init];
p.playerID = [dic objectForKey:@"id"];
p.name = [dic objectForKey:@"name"];
p.country = [dic objectForKey:@"country"];
p.club = [dic objectForKey:@"club"];
p.imageURL = [dic objectForKey:@"image"];
p.likeNumber = [dic objectForKey:@"like_number"];
p.likeTime = [dic objectForKey:@"like_time"];
p.likePlayerID = [dic objectForKey:@"like_player_id"];
p.likeDeviceID = [dic objectForKey:@"like_device_id"];
p.disLikeNumber = [dic objectForKey:@"dislike_number"];
p.disLikeTime = [dic objectForKey:@"dislike_time"];
p.disLikePlayerID = [dic objectForKey:@"dislike_player_id"];
p.disLikeDeviceID = [dic objectForKey:@"dislike_device_id"];
[players insertObject:p atIndex:i];
[p release];
}
Perhaps it thinks your players pointer is being lost at the end of the code block.
Or perhaps it is getting confused over the status of the array.
Does it complain if you create the mutable array with alloc-init instead of array: ? (Using ‘array’ without a retain does leave the whole thing on the allocation pool.)