2

皆さんこんにちは、

私は最近、いくつかのメモリリークで立ち往生しています。私が作っているアプリは次のように動作しています:

1 - ファイルをメモリに読み込みます
2 - そのファイルで読み取った値に従って画面を作成します
3 - ビューを表示します

アプリを起動して最初の画面が表示されると、今のところすべてが正常です。漏れはありません。

しかし、現在のビューから別の画面をロードしたい場合、自動解放されたオブジェクトから多くのリークが発生しました。現在のビューから新しいビューをロードすると、プロセスが似ているため、わかりません。

1 - 現在のビューの説明
2 - ファイルをメモリに読み込みます
3 - そのファイルで読み取った値に従って画面を作成します
4 - ビューを表示します

何が漏れているかの具体的な例を次に示します。

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

stringWithFormat:.. が漏れています。もう一つの例 :

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

同じ、 colorWithRed:.. が漏れています。

autoreleased オブジェクトに関する Apple のドキュメントを読みました。そして、そのような新しいプールを再作成しようとしましたが、成功しませんでした:

-(UIView)myFonctionWhoGenerateScreens:

    for () {

        NSAutoreleasePool *subPool = [[NSAutoreleasePool alloc] init];

        // There are all of the autoreleased method calls that are leaking...

        [subPool drain];

    }    
}

私は何かが欠けていると思います。誰にもアイデアがありますか?

リークバックトレースここに画像の説明を入力

どうもありがとう。

編集 :

applyPropertyName:withPropertyType:onComponent:withValue:forStyling メソッドで、リークしている関数の戻り値がどのように処理されるかを次に示します。

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
        }
    }

編集 2: これは完全なバック トレースですhttp://ganzolo.free.fr/leak/%20Leak.zip

4

1 に答える 1

1

Leak ドキュメントを見て[NSString stringWithFormat]、例としてアドレス 0xdec95c0 のオブジェクトを選択すると、Foundation、ImageIO、および CoreGraphics でオブジェクトを使用するためのバランスの取れた保持カウント操作が示されていますが、ABTwoImageItemImageLeftComponentまだ解放されていない参照が保持されています。

0   0xdec95c0   CFString (immutable)    Malloc  1   00:39.994.343   144 Foundation  +[NSString stringWithFormat:]
1   0xdec95c0   CFString (immutable)    Autorelease <null>  00:39.994.376   0   Foundation  +[NSString stringWithFormat:]
2   0xdec95c0   CFString (immutable)    CFRetain    2   00:39.994.397   0   iOS Preview App -[ABTwoImageItemImageLeftComponent setSrcProperty:]
3   0xdec95c0   CFString (immutable)    CFRetain    3   00:39.996.231   0   ImageIO CGImageReadCreateWithFile
4   0xdec95c0   CFString (immutable)    CFRetain    4   00:39.998.012   0   CoreGraphics    CGPropertiesSetProperty
5   0xdec95c0   CFString (immutable)    CFRelease   3   00:40.362.865   0   Foundation  -[NSAutoreleasePool release]
6   0xdec95c0   CFString (immutable)    CFRelease   2   01:14.892.330   0   CoreGraphics    CGPropertiesRelease
7   0xdec95c0   CFString (immutable)    CFRelease   1   01:14.892.921   0   ImageIO releaseInfoJPEG
于 2012-06-18T13:36:00.303 に答える