Reputation: 4887
Upon running my application using Leaks, I found the following leaking. The leaks occur where shimmer
and shimmerAnimation
are allocated. I cannot see what would cause this leak. Can someone point me in the correct direction?
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];
Upvotes: 0
Views: 704
Reputation: 1348
You add the shimmerAnimation object as a subview of self. That'll retain it. If self is leaking, then your shimmerAnimation would be leaking too, and since it's retaining shimmer, it would leak as well. So I'd check self to see what it's doing.
The calls to [UIImage imageNamed:...] cache the images they load. I don't think those come up as leaks though.
Oh, and you're using [UIView setAnimationDelegate:] but you're not calling [UIView beginAnimation:] which means the didStopSelector will never get called, and hence, if you're using that to remove it from the subview (which you are) it won't be. There's your most likely culprit.
[UIView setAnimationDelegate:] and friends are used for UIView animations, not for UIImageView image animations.
Upvotes: 2