I try to use autoreleasepool
in a dispatch_async
block, but it doesn't release the str
. When timerEvent is repetitively called, it will lead to a run out of memory problem.
- (void)viewDidLoad
{
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:0.0001 target:self selector:@selector(timerEvent) userInfo:nil repeats:YES];
}
-(void)timerEvent
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
@autoreleasepool {
NSString *str =[NSString stringWithFormat:@"%d and %d",px,py];
NSLog(str);
}
});
}
Thank you for your help.
----- Solved --------------- Thanks to C_X
The timer interval has been set too small. In my case, I find it should be at least 0.004. Now, it works.