【问题标题】:Why does this UIImageView animation leak?为什么这个 UIImageView 动画会泄漏?
【发布时间】:2011-04-15 00:44:14
【问题描述】:

在使用 Leaks 运行我的应用程序时,我发现以下泄漏。泄漏发生在分配shimmershimmerAnimation 的位置。我看不出是什么导致了这种泄漏。有人能指出我正确的方向吗?

float duration = .5f;
NSArray *shimmer = [NSArray arrayWithObjects:
                    [UIImage imageNamed:@"shimmer_1.png"],
                    [UIImage imageNamed:@"shimmer_2.png"],
                    [UIImage imageNamed:@"shimmer_3.png"],
                    [UIImage imageNamed:@"shimmer_4.png"],
                    [UIImage imageNamed:@"shimmer_1.png"], nil];

UIImageView *shimmerAnimation = [[UIImageView alloc] initWithFrame:[self bounds]];
[UIView setAnimationDelegate:shimmerAnimation];
[UIView setAnimationDidStopSelector:@selector(removeFromSuperview)];
[shimmerAnimation setAnimationImages:shimmer];
[shimmerAnimation setAnimationDuration:duration];
[shimmerAnimation setAnimationRepeatCount:1];
[shimmerAnimation startAnimating]; 
[self addSubview:shimmerAnimation];
[shimmerAnimation release];

【问题讨论】:

    标签: ios uiimageview core-animation


    【解决方案1】:

    您将 shimmerAnimation 对象添加为 self 的子视图。那将保留它。如果 self 正在泄漏,那么您的 shimmerAnimation 也会泄漏,并且由于它保留了微光,它也会泄漏。所以我会检查自己,看看它在做什么。

    对 [UIImage imageNamed:...] 的调用会缓存它们加载的图像。不过,我不认为这些是泄漏。

    哦,你正在使用 [UIView setAnimationDelegate:] 但你没有调用 [UIView beginAnimation:] 这意味着 didStopSelector 永远不会被调用,因此,如果你使用它从子视图中删除它(你是)它不会。你最有可能是罪魁祸首。

    [UIView setAnimationDelegate:] 和好友用于 UIView 动画,not 用于 UIImageView 图像动画。

    【讨论】:

    • 哇,把我放在我的位置上。谢谢!
    猜你喜欢
    • 2019-02-09
    • 2013-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多