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 problem



on 1/16/08 3:22 PM, email@hidden purportedly said:

You are leaking objects like mad.

>     timer = [[NSTimer alloc] initWithFireDate:[NSDate
> dateWithTimeIntervalSinceNow:currentInterval]
>                                      interval:currentInterval target:self

You *do* know that above you are setting your object property, and not a
local variable?

> -(void)setTimer:(NSTimer*)tm{
> 
>     [timer autorelease];
>     timer = [tm retain];
> }

Here you are retaining an alloced object after autoreleasing it, so it will
never be released. If you don't know why, re-read the "cocoa memory
management guidelines" (again?).

This will probably not solve your problem. It is likely that the problem
lies in code that you aren't showing, such as how the timer is being created
in the first place.

Also:

> Stepping through the debugger, I see that when inside my invalidate
> function, the timer is null, 0x0.

It always will, the first time. Once it has been created, it should no
longer be null.

Best,  

Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"


_______________________________________________

Cocoa-dev mailing list (email@hidden)

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/email@hidden

This email sent to email@hidden

References: 
 >NSTimer problem (From: 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.