Hi everyone,
I’m stuck these days on some memory leaks. The app I’m making is working like that :
1 – Loads a file into memory
2 – Create a screen according to some values read on that file
3 – Display the view
Far from now everything is normal when I start the app and get the first screen. There is no leaks.
But when I want to load an other screen from the current view I got plenty of leaks from autoreleased objects. And I don’t understand because when I load a new view from the current one the process is similar :
1 – Desctruction of the current view
2 – Loads a file into memory
3 – Create a screen according to some values read on that file
4 – Display the view
Here are some concrete example of what is leaking :
-(NSString*)pathForApplicationName:(NSString*)appName
withImage:(NSString*)imagePath {
NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [searchPaths lastObject];
return [NSString stringWithFormat:@"%@/%@/assets/www/%@",documentPath,[self convertSpacesInDashes:appName],imagePath];
}
The stringWithFormat:.. is leaking. An other example :
-(UIColor*)convertHexColorToUIColor:(NSString*)hexColor {
if ([hexColor length] == 7) {
unsigned c = 0;
NSScanner *scanner = [NSScanner scannerWithString:hexColor];
[scanner setScanLocation:1];
[scanner scanHexInt:&c];
return [UIColor colorWithRed:((c>>16)&0xFF)/255.0
green:((c>>8)&0xFF)/255.0
blue:(©&0xFF)/255.0
alpha:1.];
}
else {
return nil;
}
}
Same, colorWithRed:.. is leaking.
I’ve read apple’s documentation regarding autoreleased objects. And I’ve even tried to recreate a new pool like that, without any success :
-(UIView)myFonctionWhoGenerateScreens:
for () {
NSAutoreleasePool *subPool = [[NSAutoreleasePool alloc] init];
// There are all of the autoreleased method calls that are leaking...
[subPool drain];
}
}
I think I am missing something. Does anyone has an idea?
Leak backtrace 
Thanks a lot.
Edit :
Here is how the return of the leaking function is handled in applyPropertyName:withPropertyType:onComponent:withValue:forStyling method :
else if ([propertyType isEqualToString:@"AB_IMAGE"]) {
UIImage *image = [UIImage imageWithContentsOfFile:[self pathForApplicationName:applicationName
withImage:value]];
@try {
[component setValue:image
forKey:propertyName];
}
@catch (NSException *exception) {
#if DEBUG_CONTROLLER
NSLog(@" %@ Not key-value compliant for <%@,%@>",component,propertyName,image);
#endif
}
}
Edit 2 :
Here is the complete back trace http://ganzolo.free.fr/leak/%20Leak.zip
Looking at your Leak document, and picking the
[NSString stringWithFormat]object at address 0xdec95c0 as an example, it shows balanced retain count operations for the Foundation, ImageIO, and CoreGraphics use of the object butABTwoImageItemImageLeftComponentis still holding an unreleased reference.