I would expect, at "A", for the timer to have any retain count of at least one, and an equal number of releases pending in your autorelease pool. Maybe the run loop's autorelease pool is getting popped or drained as a side effect of adding the timer or something. If you really want to figure it out, just make a trivial subclass of NSTimer that implements retain, release, autorelease, and maybe dealloc. Make them log, set breakpoints on them, take them apart and see what makes them tick.

-Tom

On Mar 13, 2008, at 6:37 PM, Brian Greenstone wrote:

I'm hoping someone can shed some light on this for me. I'm getting some unusual retainCount values from the following code:

        NSTimer *theTimer;
        
        theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                                        target:         self
                                                        selector:       
@selector(timerCallback)
                                                        userInfo:       nil
                                                        repeats:        YES];

        NSLog(@"A: retain count: %i", [theTimer retainCount]);

[[NSRunLoop currentRunLoop] addTimer: theTimer forMode: NSDefaultRunLoopMode];

        NSLog(@"B: retain count: %i", [theTimer retainCount]);


The output I get is:

        A: retain count: 2
        B: retain count: 2


But that shouldn't be, right? Shouldn't the retainCount of theTimer be 1 after scheduledTimerWithTimeInterval? Then shouldn't it be bumped up to 2 after adding the timer to the Run Loop? It appears that the retain count is starting at 2 which is wrong, and then not being incremented by addtimer which is wrong. In the end the count is still 2, so it is valid, but I'm confused why the counts are doing this.


Thanks,

-Brian




_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/tom%40omnigroup.com

This email sent to [EMAIL PROTECTED]


_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to