Reputation: 235
I am currently using a UIImageView
to animate a series of images depending on a button pressed by the user. I have about 5 different sets of images, that i have created in NSArrays
, such as this:
-(void)initiateAnimations {
punchani = [NSArray arrayWithObjects:
[UIImage imageNamed:@"punch0001.png"],
[UIImage imageNamed:@"punch0002.png"],
[UIImage imageNamed:@"punch0003.png"],
[UIImage imageNamed:@"punch0004.png"],
[UIImage imageNamed:@"punch0005.png"],
[UIImage imageNamed:@"punch0006.png"],
[UIImage imageNamed:@"punch0007.png"],
[UIImage imageNamed:@"punch0008.png"],
[UIImage imageNamed:@"punch0009.png"],
[UIImage imageNamed:@"punch0010.png"],
[UIImage imageNamed:@"punch0011.png"],
[UIImage imageNamed:@"punch0012.png"],nil];
}
And then i am using the standard animation code to loop them once:
player.animationImages = punchani;
player.animationDuration = 0.50;
player.animationRepeatCount = 1;
[player startAnimating];
However, as i load more and more/different images into the UIImageView
, i eventually get an output that a Memory warning as follows: (subsituted my actual executable with 'appname')
2013-03-15 20:52:23.065 AppName[2080:907] Received memory warning.
I knew this would probably happen, but ARC forbids me from releasing the arrays. How can i fix this leak? thanks
Upvotes: 2
Views: 2939
Reputation: 6954
UIImage imageNamed: caches the images and will release the memory on it's own schedule. Use
+ (UIImage *)imageWithContentsOfFile:(NSString *)path
to load memory directly
Try this answer as well. Remove array of images when animation is over
Upvotes: 4