In another thread about NSDate memory leak, I learned that sometimes I need to wrap code inside an @autoreleasepool. But I get more puzzled when I really try to refactor my code.
Here is my problem. I have a NSCondition dervived class which implements a convenience method:
- (BOOL)wait:(NSTimeInterval)timeToWait
{
NSDate* date = [[NSDate date] dateByAddingTimeInterval:timeToWait];
BOOL f = [self waitUntilDate:date];
return f;
}In some place, I need to poll on something (don't argue with me about disadvantages about polling):
- (void)monitor
{
while (YES)
{
[_guard lock];
if(_guard.stop)
{
break;
}
[_guard wait:DEFAULT_POLL_INTERVAL];
[self check_visibility];
[_guard unlock];
}
}Now I'm bewildered about where to put @autoreleasepool, in the outer loop or directly in the wait: method.
Thanks for any suggestions.