ARC导致大量遗弃的记忆

时间:2012-01-15 08:14:36

标签: ios memory memory-management instruments automatic-ref-counting

我在iOS 5发布时将整个项目转换为ARC,但还没有EXC_BAD_ACCESS。但是,我最近一直在查看仪器中的内存监视器,并注意到每当我重复执行相同的任务时(例如拍照),相当多的对象都被添加到堆中。然而,添加的对象看起来似乎不应该被保留。这些例子包括:

- (NSString *)imagesDirectory {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *folderDirectory = [documentsDirectory stringByAppendingPathComponent:@"Images"];
    NSFileManager *fileManager = [[NSFileManager alloc] init];
    [fileManager createDirectoryAtPath:folderDirectory withIntermediateDirectories:YES attributes:nil error:nil];
    fileManager = nil;
    return folderDirectory;

}

它表示fileManager对象未被释放,而且:

UIImageView *transitionImage = [[UIImageView alloc] initWithImage:thumbnail];
        transitionImage.center = primeReviewButton.center;
        transitionImage.bounds = primeReviewButton.bounds;
        transitionImage.transform = orientationTransform;
        transitionImage.alpha = 0.0;

        [self.cameraView insertSubview:transitionImage belowSubview:photoNumberBadge];

        [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionAllowUserInteraction
                         animations:^{
                             transitionImage.alpha = 1; 
                         }
                         completion:^(BOOL finished){
                             transitionImage.alpha = 0;
                             transitionImage.image = nil;
                             [transitionImage removeFromSuperview];
}];

它表示animateWithDuration:以某种方式对废弃的记忆负责。

我已尽我所能让这些对象像他们应该的那样被释放(所有Memory Monitor都可以告诉我他们所有人都是Malloc-ed一次,并且保留计数为1)。这是ARC的错误吗?

0 个答案:

没有答案