我有一个表格视图,在加载时会创建一个人对象
人.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
人.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... 行,说明这是泄漏的位置。
为什么会漏在那里?