RE: Unwanted retain
RE: Unwanted retain
- Subject: RE: Unwanted retain
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Wed, 4 Feb 2004 18:32:26 -0500
There's nothing to fix. The timer is retaining your object until the timer
is dealloced. That's normal, expected behavior. It's just like when an
NSArray retains an object added to it. If you release the object, it still
has a non-zero retain count and the array can still access it. Your app
crashes when you release twice because the timer eventually tries to get to
the object that you double-released.
Once you are done with your object and have released (not dealloced, I hope)
it, you have no further role to play. It's up to the timer to release your
object, which may cause the object's deallocation. Or maybe not, if, for
example, there's an NSArray that contains the object, too.
If you are not smacking your head at how obvious this is, go back and read
about memory management.
Jonathan
>
-----Original Message-----
>
From: email@hidden
>
[mailto:email@hidden]On Behalf Of Lorenzo
>
Sent: Wednesday, February 04, 2004 5:41 PM
>
To: email@hidden
>
Subject: Unwanted retain
>
>
>
Hi,
>
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?
>
>
Best Regards
>
--
>
Lorenzo
>
email: email@hidden
>
_______________________________________________
>
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.
_______________________________________________
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.