Re: NSTimer problem
Re: NSTimer problem
- Subject: Re: NSTimer problem
- From: email@hidden
- Date: Thu, 17 Jan 2008 12:21:33 -0600 (CST)
- Importance: Normal
> 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?).
timer is an instance variable, not a local variable. Sorry if that wasn't
clear.
I have read the guidelines. This one is technique 2 on this page:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAccessorMethods.html#//apple_ref/doc/uid/TP40003539
But I have used all three listed on the page, with 3 being the most
typical for my uses. If I understand the process correctly, the
autorelease tells the runtime to decrement the retain at some point in
future, most likely after the function returns. The retain increments the
retain count immediately, so "at point in the future" there should an
offset in retain/releases and the retain count for my object should be
correct. Am I misunderstanding something? This is important to me since I
have quite a bit of code written like this and I just don't find leaks
using tools such as instruments now or in the past with leaks or
ObjectAlloc.
>
> 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.
So how can I get a valid reference to the timer?
>
> Best,
Thanks for the reply, I'll keep working with it and read the MM guide again.
>
> 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:
This email sent to email@hidden