Sharanya K M
Sharanya K M

Reputation: 1805

Received Memory Warning on iPad

I am developing an app on iPad which has only animations. I am using around 400 JPEG images to make animations. The size corresponds to 7MB. But the animation stops and app crashes after animating 50 images. I am using UIImageView in NIB as IBOutlet and changing the images in code using NSTimer. The app crashes showing the message Received memory warning. I have checked using Instruments tool and found no leaks.

Any suggestions are appreciated.

code

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self callTimer];
}

-(void) callTimer
{
tempView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
[self.view addSubview:tempView];
animationTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self     selector:@selector(animateCharacter) userInfo:nil repeats:YES];
}

-(void) animateCharacter
{
imageNumber++;
if(imageNumber <= 400)
{
    tempView.image = [UIImage imageNamed:[NSString stringWithFormat:@"body%d.jpg",imageNumber]];

}
else
{
    //tempView.image = [UIImage imageNamed:[NSString stringWithFormat:@"pose.png",imageNumber]];
    imageNumber = 0;
    tempImageNumber = 0;
    [tempView removeFromSuperview];
    [tempView release];
    tempView = nil;
    [animationTimer invalidate];
    animationTimer = nil;
}

}

Upvotes: 1

Views: 466

Answers (2)

Ajay Malviya
Ajay Malviya

Reputation: 131

you are not invalidate or nil your timer if you are invalidate or nil then you are not receive memory warning.

animationTimer=nil; [animationTimer invalidate];

Upvotes: 0

Nimit Parekh
Nimit Parekh

Reputation: 16864

Are you using multiple Timer for changing the image for the particular time duration?

As my experience you need to real time to invalidate timer and nil the value of time so it may solve your problem.

Also more information can you put code here so we can more identify about your problem.

Thanks.

Upvotes: 2

Related Questions