Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTimer retains its target ???



On Tuesday, Apr 29, 2003, at 11:21 Europe/Stockholm, Tobias Hermann wrote:

That is really strange, because I thought TARGETS simply are references! And the target I pass here is the creator of the Timer, so it also makes no sense that the Timer retains its parent ?!

...but the timer object doesn't know what a "parent" is, or who is creating it, so it cannot make that kind of decision.

Problem is that I want to invalidate the timer within the dealloc method of the target. But that now never gets called because the timer retained it :-(
Is that a bug or am I misunderstanding something ?

It's working per design, so it's not a bug.

I have created a separate scheduler class that doesn't retain it's targets for similar purposes, you might do the same if you can't re-design your code. Something like this:

@interface MyScheduler : NSObject
{
@private

NSMutableSet *events;
}

+ (void) addSubscriber:(id) subscriber toAction:(SEL) action afterDelay:(NSTimeInterval) secondsDelay;
+ (void) removeSubscriber:(id) subscriber;

@end

j o a r
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >NSTimer retains its target ??? (From: Tobias Hermann <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.