user997841
user997841

Reputation: 87

Narrowing down memory leak

I am still searching for a way to solve my memory leaks. For the moment I have a leak at this line of code.

return [UIImage imageWithContentsOfFile:path];

Anybody an idea?

Thx in advance!

- (UIImage *)imageAtIndex:(NSUInteger)index {
    // use "imageWithContentsOfFile:" instead of "imageNamed:" here to avoid caching our images
    NSString *imageName = [self imageNameAtIndex:index];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:imageName];
    //NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:@"jpg"];

    return [UIImage imageWithContentsOfFile:path];
}

- (void)configurePage:(ImageScrollView *)page forIndex:(NSUInteger)index

{

page.index = index;
page.frame = [self frameForPageAtIndex:index];

// To use full images instead of tiled images, replace the "displayTiledImageNamed:" call
// above by the following line:
// [page displayImage:[self imageAtIndex:index]];
[page displayImage:[self imageAtIndex:index]];

}

Upvotes: 1

Views: 214

Answers (1)

bbum
bbum

Reputation: 162712

When leaks identifies a line of code as being a leak, it is not claiming that said line of code is the actual leak. Only that said line of code is the source of the allocation that was leaked.

Thus, the image returned by imageWithContentsOfFile: is being over-retained somewhere else and it is your job to find out where.

Which is generally pretty easy; turn on the "retain tracking" [IIRC] checkbox on the little configuration panel of the Allocations instrument, run your app, and then click through one of the leaked UIImages to see a list of exactly where the image was retained and released. One of those retains will not be balanced and that is your leak.

Though slightly orthogonal, I describe how to do this in a post about using Heapshot Analyais to find leaks.

Upvotes: 3

Related Questions