Remember that NSTimer Retains Its Target
#import <Foundation/Foundation.h>
@interface EOCClass : NSObject
- (void)startPolling;
- (void)stopPolling; @end
@implementation EOCClass
{
NSTimer *_pollTimer;
}
- (id)init
{
return [super init];
}
- (void)dealloc
{
[_pollTimer invalidate];
}
- (void)stopPolling
{
[_pollTimer invalidate];
_pollTimer = nil;
}
- (void)startPolling
{
_pollTimer =
[NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:@selector(p_doPoll)
userInfo:nil
repeats:YES];
}
- (void)p_doPoll
{
// Poll the resource
}
@end

- (void)startPolling
{
__weak EOCClass *weakSelf = self;
_pollTimer =
[NSTimer eoc_scheduledTimerWithTimeInterval:5.0
block:^{
EOCClass *strongSelf = weakSelf;
[strongSelf p_doPoll];
}
repeats:YES];
}