NSData内存泄漏...指向NSConcreteData!

时间:2011-07-01 12:34:17

标签: iphone memory-leaks nsdata

我有内存泄漏,无法搞清楚。基本上,我在这里做的是将图像拉入Mutable Dictionary并返回字典。

- (NSMutableDictionary *)loadImageDataGroup:(NSUInteger)index {

int lim = 5;
int sta = 0;
if (index > lim) {
    sta = index-lim;
}
int fin = (((lim*2)+1)+sta);
if (fin > [self imageCount]) {
    sta = ([self imageCount]-((lim*2)-1));
    fin = [self imageCount];
}

BOOL firstTime = NO;
if ([imagesLoaded count] == 0) {
    firstTime = YES;
}

NSMutableDictionary *tempDict = [[[NSMutableDictionary alloc] init] autorelease];

for (int i = sta; i < fin; i++) {

    NSString *imageName = [self imageNameAtIndex:i];

    if ([imagesLoaded valueForKey:imageName] == nil) {

        // This is the Memory Leak...at least that is where Leaks is pointing me.
        NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageName]];
        [tempDict setObject:imageData forKey:imageName];

    } else {
        [tempDict setObject:[imagesLoaded valueForKey:imageName] forKey:imageName];
    }

}

return tempDict;

}

泄漏位于NSData = * imageData点,当我将其泄漏时,它指向NSConcreteData。

1 个答案:

答案 0 :(得分:0)

看着你的代码,我没有看到任何明显的错误。请注意,仪器可能会产生误报。

请参阅以下内容:

Instruments showing false leak?