I am working on an iphone app where I have to pick images from different folder after a button click. I have 5 UIButtons on UI and 5 Images folder each contains near about 100 images. I use same array for all UIButtons images. I fill array by following function :
-(void)playAnimations:(NSString*)animationName:(int)photoCount
{
NSString *photoPathName;
UIImage *object = [[UIImage alloc]init];
for (int i=1; i<photoCount+1; i++)
{
NSString *imagesName=@"";
if (i<10) {
imagesName =[photoPathName stringByAppendingFormat:@"000%d",i];
}
else if(i>9 && i<100)
imagesName =[photoPathName stringByAppendingFormat:@"00%d",i];
else if(i>99 && i<1000)
imagesName =[photoPathName stringByAppendingFormat:@"0%d",i];
object = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:imagesName ofType:@"png"]];//[UIImage imageNamed:imagesName];
[self.arrayImagesName addObject:object];
}
self.animationImage.animationImages = self.arrayImagesName;
self.animationImage.animationDuration =durationTime ;// defaults is number of animation images * 1/30th of a second
self.animationImage.animationRepeatCount = 1; // default is 0, which repeats indefinitely
[self.animationImage startAnimating];
}
I am getting memory leak again and again from second click(it runs proper on first click) and app gets crashes.
Where I am making mistake? please help/suggest me right way to implement it.
Thanks.