If it's a repeating timer, then you can call invalidate and assign it to nil in 
the target selector method. This approach wouldn't require a class reference to 
it either.



________________________________
 From: Gordon Apple <[email protected]>
To: [email protected] 
Sent: Saturday, January 12, 2013 10:49 AM
Subject: Could somebody please fix NSTimer?
 
When compiled under ARC, NSTimer should have a weak, not strong, reference
to its target.  When the timer starts to fire, check the reference for nil
and invalidate itself.  Come on guys, how hard is that?  You wouldn¹t even
have to keep a reference to it, unless you want to invalidate it before the
target deallocates.

Trying to invalidate an NSTimer in dealloc doesn¹t work, because dealloc
will never get called due to the strong reference in NSTimer.  Leaks galore.
Lots of mentions of this when you Google it for retain cycles.

You can¹t subclass NSTimer, but you can wrap it.  I did this in iOS to
create a suspendable timer.  Maybe I can do something similar for Mac to
make it behave properly.
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/howlewere%40yahoo.com

This email sent to [email protected]
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to