开发者

iPhone - Objective-C NSURL Memory Leaks galore

I am getting the following memory leak when using NSURL. I use this method in quite a few different places and receive memory leaks all the time using the Leaks instruments.

Object Management:

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

Where it's used:

HJManagedImageV *mi = [[[HJManagedImageV alloc] initWithFrame:CGRectMake(self.myHeaderView.profilePictureI开发者_如何学GomageView.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];
}

iPhone - Objective-C NSURL Memory Leaks galore


You can use stack trace to determine the place of leak.

Edit:

make sure you are releasing the mi.url in dealloc method:

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

   [super dealloc];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜