I have a subclassed UIView which is not being deallocated. I know that only one class is creating an instance of my view. I have an NSTimer ivar in my view. If I comment out that timer and when I tap a cancel button that is on this view controller, dealloc in this view is called. If I don't comment out the timer, the dealloc is never called.
//CustomUIView
- (id) initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_pollTimer = [[NSTimer scheduleTimerWithTimeInterval:0.2 target:self selector:@selector(onPollTimerFired:) userInfo:nil repeats:YES] retain];
}
}
I want to keep a reference to this timer because there are times when I wish to pause the timer. Now, I could have a property on my view for the timer and in the dealloc method of the class that has a reference to my custom uiview, I could invalidate it before releasing said view. I don't really like this approach because I don't want to expose this timer to outside entities.
Anyone have any ideas?