iPhone - Objective-C NSURL内存泄漏丰富

时间:2011-02-13 10:33:02

标签: iphone objective-c memory-leaks nsurlconnection core-foundation

使用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];

的dealloc:

- (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];
}

enter image description here

1 个答案:

答案 0 :(得分:1)

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

编辑:

确保以dealloc方式发布mi.url:

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

   [super dealloc];
}