0

UIProgressView によって監視されるタスクが完了すると、メインスレッドで更新された UIProgressView とモーダルウィンドウを備えたアプリ (iPad、Xcode 4.6、iOS 6.x) を開発しています。コードから UIProgressView とスレッド呼び出しを削除すると、リークは発生しません。手動で作成した UIProgressView と StoryBoard の両方で試しました。プログラムは ARC を使用します。

2 つのリークは、WebCore/WebThreadCurrentContext [Malloc 16 バイト] と UIKit/GetContextStack [Malloc 64 バイト] です。

@interface KICreateImportFileViewController ()
...
@property (strong, nonatomic) UIProgressView *convertedRecordsProgressView;
@end

@implementation KICreateImportFileViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    ...

    // config the UIProgressView
    CGRect pFrame = CGRectMake(20, 100, 500, 9);
    self.convertedRecordsProgressView = [[UIProgressView alloc] initWithFrame:pFrame];
    self.convertedRecordsProgressView.progressViewStyle = UIProgressViewStyleDefault;
    [self.view addSubview:self.convertedRecordsProgressView];
}

- (void)viewDidAppear:(BOOL)animated
{
    // listen for a NSNotification with info regarding process from class KITestParser
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(updateProgressViewWhenNotified:)
                                                 name:@"KITestParser:Progress Updated"
                                               object:self.originalFile.testParser];

    // Begin the background process that will update the UIProgressView
    [self performSelectorInBackground:@selector(createImportFileInBackground:) withObject:nil];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [super viewWillDisappear:animated];
}

#pragma mark - Notifications
-(void)updateProgressViewWhenNotified:(NSNotification *)notification
{
    NSNumber* progress = (NSNumber *)[notification.userInfo valueForKey:@"progressRatio"];
    [self updateProgressViewOnMainThread:progress];
}

#pragma mark - Private class methods
- (void)createImportFileInBackground:(id)obj
{
    // Background processes aren't automatically protected by ARC unless you wrap the function in the auto-release pool.
    @autoreleasepool {
        [self.originalFile createImportFile];
    }
}

- (void)updateProgressViewOnMainThread:(NSNumber *)progress
{
    [self performSelectorOnMainThread:@selector(updateProgressView:) withObject:progress waitUntilDone:NO];
}

- (void)updateProgressView:(NSNumber *)progress
{
    [self.convertedRecordsProgressView setProgress:[progress floatValue] animated:YES];
}

@end

質問 1: createImportFileInBackground から呼び出されるすべてのメソッドを @autoreleasepool{} でラップする必要がありますか? もしそうなら、それはこのクラスに通知を送り返している他のクラスのメソッドを含みますか?

質問 2: 漏れの原因となっている何かが欠けているのでしょうか?

ヘルプ/提案をいただければ幸いです。前もって感謝します!ティム

4

1 に答える 1

0

簡単な答え: ARC を使用しているので、心配する必要はありません。

詳細:これまでに行ったすべてのARCプロジェクトでこれを見てきました。リーク ツールは、フレームワーク コードのリークを特定します。それらは本当に漏れですか?ツールは誤検知を与えていますか? 回答: 誰が気にしますか。それらが本当のリークであるかどうかを知っていたとしても、アップルにバグを報告することが最善の解決策です. 頼ることはできません。あなたが取ることができる行動はありません。気にしないで。

于 2013-03-01T23:56:25.223 に答える