Re: Unwanted retain
Re: Unwanted retain
- Subject: Re: Unwanted retain
- From: Lorenzo <email@hidden>
- Date: Thu, 05 Feb 2004 01:46:01 +0100
Hi,
thank to everybody.
Thanks for explaining so well the timer retains the target object.
My error was that I released the timer within the dealloc object method.
This way:
- (void)dealloc
{
if(renderTimer){
[renderTimer invalidate];
[renderTimer release];
renderTimer = nil;
}
[super autorelease];
}
So when my superclass released my object, the object could have not been
deallocated properly.
Now I relase the timer using a different method like
[myObject relaseTimer];
[myObject release];
Now it works fine.
Sorry for my english.
Best Regards
--
Lorenzo
email: email@hidden
>
From: Chris Parker <email@hidden>
>
Date: Wed, 04 Feb 2004 15:26:06 -0800
>
To: Lorenzo <email@hidden>
>
Cc: email@hidden
>
Subject: Re: Unwanted retain
>
>
Hi Lorenzo,
>
>
On Feb 4, 2004, at 2:41 PM, Lorenzo wrote:
>
>
> I noted that when I call scheduledTimerWithTimeInterval, my self object
>
> retainCounter increments by one.
>
> -------
>
> NSLog(@"A self retain count %d", [self retainCount]);
>
> renderTimer = [[NSTimer scheduledTimerWithTimeInterval:timeInterval
>
> target:self selector:@selector(fireTheTimer)
>
> userInfo:nil
>
> repeats:YES] retain];
>
> NSLog(@"B self retain count %d", [self retainCount]);
>
> -------
>
>
>
> I get:
>
> -------
>
> A self retain count 1
>
> B self retain count 2
>
> -------
>
>
>
>
>
>
>
> Then if I deallocate one time only the object "self" from the class I
>
> created it, I don't see the object self deallocated. I have to
>
> deallocate it
>
> twice, but then my app crashes.
>
>
>
> Why? Do you know how to fix this?
>
>
The timer is trying to guarantee that the object receiving the message
>
will be around when it's time to fire - so it's placing a retain on the
>
target.
>
>
So you've got one retain from you yourself creating the object - that
>
one you should release.
>
>
When the timer goes away, it'll release your object.
>
>
As a general rule, you shouldn't be using -retainCount to decide
>
whether or not to release something.
>
>
.chris
>
>
--
>
Chris Parker
>
Cocoa Frameworks Engineer
>
Apple Computer, Inc.
_______________________________________________
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.