我有一个表格视图,在加载时创建一个人物对象。
Person.h
在我的UITableView方法cellAtRowForIndexPath中,我正在创建每个人物对象并像这样分配图像属性...
Person.h
#import <UIKit/UIKit.h>
#import "TwitterHelper.h"
@interface Person : NSObject {
NSDictionary *userInfo;
NSURL *image;
NSString *userName;
NSString *displayName;
NSArray *updates;
}
/*
@property (retain) NSString *userName;
@property (retain) NSString *displayName;
@property (retain) NSDictionary *userInfo;
*/
@property (nonatomic, copy) NSURL *image;
@property (retain) NSArray *updates;
- (id)initWithUserName:userName;
@end
Person.m
#import "Person.h"
@implementation Person
/*
@synthesize userName;
@synthesize displayName;
@synthesize userInfo;
*/
@synthesize image;
@synthesize updates;
- (id)initWithUserName:(NSString *)user{
userName = user;
userInfo = [TwitterHelper fetchInfoForUsername:user];
displayName = [userInfo valueForKey:@"name"];
image = [NSURL URLWithString:[userInfo valueForKey:@"profile_image_url"]];
updates = [TwitterHelper fetchTimelineForUsername:userName];
return self;
}
- (void)dealloc
{
/*
[userName release];
[displayName release];
[updates release];
[userInfo release];
[image release];
*/
[super dealloc];
}
@end
在我的UITableView方法cellAtRowForIndexPath中,我正在创建每个人物对象并像这样分配图像属性...
Person *person = [[Person alloc] initWithUserName:userName];
NSData *data = [[NSData alloc] initWithContentsOfURL:person.image];
[data release];
当我在Instruments中运行时,它会突出显示NSData *data...这一行,并指出内存泄漏发生在那里。
为什么会在那里发生内存泄漏?