I recently encountered an alarming problem that I have never been
aware of, and I'd like to ask about the best practice to handle it.

Is it true that any object (let's call it Controller) that owns an
NSTimer, scheduled to fire a method (let's call it -timerDidFire) of
the same Controller, creates a circular reference and causes the
Controller to never be released and the timer never stop triggering?

It looks like scheduling the timer causes the run loop to retain a
reference to the object that implements -timerDidFire, in this case
it's the Controller. Is this true? Then this is a circular reference,
right?

In this case, if [_timer invalidate]; is called only in Controller's
dealloc, then the timer never stops firing?

Which is the best way to prevent this problem? Currently I'm thinking
about some kind of -[controller disconnect]; method that I need to
call before [controller release]; in controller's parent object, but
that seems a bit unwieldy solution.

Any other ideas/considerations? Thanks!
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to