On iPhone.. Why would code such as this cause memory leak? after 2 minutes the net bytes have doubled.
All I’m doing is moving a ball round the screen with an NSTimer calling the below method.
Any ideas?
- (void)nextFrame:(NSNotification *)notification {
ballInstance.frame = CGRectMake(value, 0, 320, 480);
}
here is the ‘full’ code, new project, still behaves the same. It moves a jpg accross the screen, and as it does memory is massively consumed. If I remove the ‘++’ from ‘value’ memory is fine. (in otherwords have a static graphic) So…. is the image being cached is the question?
If so how can i stop it reaching astronomical sizes?
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window makeKeyAndVisible];
NSTimer * nSTimer =[NSTimer scheduledTimerWithTimeInterval: .02
target: self
selector: @selector(tick)
userInfo: nil
repeats: YES];
value =0;
}
- (void)tick {
NSLog(@"tick");
myOutlet1.frame = CGRectMake(value++, 0, 320, 480);
}
The posted code has no leak. The problem is elsewhere.
If you know that there’s a leak inside of
nextFrame:, it has to be in-[Ball setFrame:]because it is the only message sent in this method.