I will like to know how to release the memory from the animating array, somehow in instruments the animating picture are eating up 24MB of real memory. what should i do to release the memory ? the total picture file size are about 3MB in Mac OS.
*EDIT:*Cool, i enabled the ARC setting in the build setting, no longer crashing...but memory usages still hovering around 80 - 120mb physical memory.....
this is the line that run for the image.
-(void)defaultSetup
{
self.imageArray = [[NSMutableArray alloc] initWithObjects:
[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"default/d7.jpg"]],
[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"default/d9.jpg"]],
[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"default/d11.jpg"]],
[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"default/d27.jpg"]],
[UIImage imageWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"default/d6.jpg"]],
nil];
self.defaultID = [[NSMutableArray alloc] initWithObjects:@"0",@"1",@"2",@"3",@"0",nil];
self.defaultImageCaption = [[NSMutableArray alloc] initWithObjects:@"Ver",@"Green",@"Red",@"Cru",@"East",nil];
NSUInteger count = [self.defaultID count];
NSLog(@"Count %i",[self.defaultID count]);
NSMutableArray *randomImgName = self.imageArray;
NSMutableArray *randomID = self.defaultID;
NSMutableArray *randomName = self.defaultImageCaption;
for (NSUInteger i = 0; i < count; ++i) {
// Select a random element between i and end of array to swap with.
int nElements = count - i;
int n = (arc4random() % nElements) + i;
[randomName exchangeObjectAtIndex:i withObjectAtIndex:n];
[randomImgName exchangeObjectAtIndex:i withObjectAtIndex:n];
[randomID exchangeObjectAtIndex:i withObjectAtIndex:n];
}
self.imageArray = randomImgName;
self.defaultID=randomID;
self.defaultImageCaption=randomName;
NSLog(@"default filename %@",self.defaultImageCaption);
NSLog(@"default ID %@",self.defaultID);
self.imageViewTop.alpha = 1.0;
self.imageViewBottom.alpha = 0.0;
self.imageViewBottom = [[[UIImageView alloc] initWithFrame:CGRectMake(0,44,320,367)] autorelease];
self.imageViewTop = [[[UIImageView alloc] initWithFrame:CGRectMake(0,44,320,367)] autorelease];
[self.view addSubview:imageViewTop];
[self.view addSubview:imageViewBottom];
self.buttonCaption = [UIButton buttonWithType:UIButtonTypeCustom];
//default placement
self.buttonCaption.frame = CGRectMake(245, 365, 70, 30);
//[buttonCaption setTitle:@"\u00A9" forState:UIControlStateNormal];
[self.buttonCaption addTarget:self action:@selector(buttonCheck) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.buttonCaption];
[self nextAnimation:buttonCaption.frame.size.width];
}
-(void)nextAnimation:(float)previousWidth {
//picture loop
imageViewTop.image = imageViewBottom.image;
imageViewBottom.image = [imageArray objectAtIndex:[imageArray count] - 1];
[imageArray insertObject:imageViewBottom.image atIndex:0];
[imageArray removeLastObject];
imageViewTop.alpha = 1.0;
imageViewBottom.alpha = 0.0;
//Name Caption
NSString * tempCaption = [defaultImageCaption objectAtIndex:[defaultImageCaption count]-1];
self.dID = [defaultID objectAtIndex:[defaultID count]-1];
// make the buttons content appear in the top-left
[buttonCaption setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
[buttonCaption setContentVerticalAlignment: UIControlContentVerticalAlignmentCenter ];
[defaultImageCaption insertObject:tempCaption atIndex:0];
[defaultImageCaption removeLastObject];
[defaultID insertObject:dID atIndex:0];
[defaultID removeLastObject];
[UIView animateWithDuration:1 delay:2 options:0
animations:^{
[buttonCaption setTitle:tempCaption forState:UIControlStateNormal];
//NSLog(@"Name %@",tempCaption );
//NSLog(@"ID %@",dID);
}
completion:^(BOOL completed)
{
}];