0

使用NSURL. 我在很多不同的地方使用这种方法,并且一直使用 Leaks 工具接收内存泄漏。

对象管理:

self.objManager = [[HJObjManager alloc] init];
NSString *cacheDirectory = [NSHomeDirectory() stringByAppendingPathComponent:@"/Library/Caches/App"];
HJMOFileCache *fileCache = [[[HJMOFileCache alloc] initWithRootPath:cacheDirectory] autorelease];
self.objManager.fileCache = fileCache;
fileCache.fileCountLimit = 100;
fileCache.fileAgeLimit = 60*60*24;
[fileCache trimCacheUsingBackgroundThread];

使用地点:

HJManagedImageV *mi = [[[HJManagedImageV alloc] initWithFrame:CGRectMake(self.myHeaderView.profilePictureImageView.bounds.origin.x,
                                                                         self.myHeaderView.profilePictureImageView.bounds.origin.y,
                                                                         self.myHeaderView.profilePictureImageView.bounds.size.width,
                                                                         self.myHeaderView.profilePictureImageView.bounds.size.height)] autorelease];

mi.layer.masksToBounds = YES;
mi.layer.cornerRadius = 8.0;
mi.layer.borderColor = [[UIColor blackColor] CGColor];
mi.layer.borderWidth = 1.0;

mi.url = [NSURL URLWithString:profilePictureUrl];
[mi showLoadingWheel];

[self.myHeaderView.profilePictureImageView addSubview:mi];
[self.objManager manage:mi];

交易地址:

- (void)viewDidUnload {
    self.tv = nil;
    self.friends = nil;
    self.sortedFriends = nil;
    self.detailView = nil;
    self.profileView = nil;
    self.objManager = nil;
    [super viewDidUnload];
}

- (void)dealloc {
    [tv release];
    [friends release];
    [sortedFriends release];
    [detailView release];
    [profileView release];
    [objManager release];
    [super dealloc];
}

在此处输入图像描述

4

1 回答 1

1

您可以使用堆栈跟踪来确定泄漏的位置。

编辑:

确保您在 dealloc 方法中释放 mi.url:

-(void) dealloc {
   //some other releases
   self.url = nil;

   [super dealloc];
}
于 2011-02-13T10:38:15.803 回答