ARC 导致大量废弃内存

发布于 2024-12-26 23:37:55 字数 1772 浏览 5 评论 0原文

当 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 对象没有被释放,而 this:

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: 在某种程度上对废弃的内存负责。

我已经尽了一切努力让这些对象像它们应该的那样被释放(内存监视器可以告诉我关于它们的所有信息是它们都被 Malloc 了一次,并且保留计数为 1)。这是 ARC 的错误吗?

I converted my entire project to ARC when iOS 5 was released, and haven't had a EXC_BAD_ACCESS yet. However, I've been looking through the Memory Monitor in Instruments lately, and notice that a fair number of objects are being added to the heap whenever I do the same task repeatedly (for instance taking a picture). However, the objects that are added definitely seem like they SHOULDN'T be kept around. Such examples include:

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

}

where it says the fileManager object isn't being released, and this:

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

where it says the animateWithDuration: is somehow responsible for the abandoned memory.

I've tried everything I can to get these objects to be released like they should (all Memory Monitor can tell me about them is that they were all Malloc-ed once, and have a retain count of 1). Is this a bug with ARC?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文