I have NSTimer shooting at 60 frames per second. It updates the C ++ model and then draws through Quartz 2D. This works well, but memory builds up quickly, although I don't allocate anything. There are no leaks in the devices, but many CFRunLoopTimers (I think from a repeating NSTimer ?) NSTimer accumulate. Clicking on a window or pressing a key clears most of them, which, apparently, indicates that the auto-advertisement pool does not merge often enough. Should I rely on events to quote the auto-resource pool, or is there a better way to clear the memory?
Any help is appreciated, thanks
-Sam
Creating a timer ( timer - ivar):
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f / 60 target:self selector:@selector(update:) userInfo:nil repeats:YES];
update: method:
- (void)update:(NSTimer *)timer { controller->Update(); [self.view setNeedsDisplay:YES]; }
Update:
After I got into it a bit, I made a few extra observations.
1.) [self.view setNeedsDisplay:YES] seems to be the culprit in the appearance of these CFRunLoopTimers . Replacing it with [self.view display] fixes the problem, but at the expense of performance.
2.) Reducing the frequency to 20-30 frames per second and saving `[self.view setNeedsDisplay: YES] 'also causes the problem to go away.
This seems to imply that setNeedsDisplay: doesn't want to be called much (maybe more time per second can be displayed?). Frankly, I canβt understand that the problem with "relocation", if all this does, is to show that the view will be redrawn at the end of the eventloop.
I am sure that something is missing here, and any additional help is appreciated.