Re: Unwanted retain
Re: Unwanted retain
- Subject: Re: Unwanted retain
- From: Kyle Moffett <email@hidden>
- Date: Wed, 4 Feb 2004 18:52:24 -0500
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Feb 04, 2004, at 17:41, Lorenzo wrote:
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
-------
Exactly, the timer retains your object because it keeps a pointer to it
in order
to send it a message later when the timer fires.
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.
So in the object that created your object you [someObject release], and
it
isn't deallocated. That is by design, because the timer still has a
reference
to your object. Perhaps you should add an extra method -
(void)removeTimer;
that deletes the timer and breaks the circular reference loop, then you
can
[someObject release
Why? Do you know how to fix this?
Everything you described is by design, and doesn't need fixing. Please
read
the Memory Management Cocoa docs here:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/
index.html
Cheers,
Kyle Moffett
- -----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCM/CS/IT/U d- s++: a17 C++++>$ UB/L/X/*++++(+)>$ P+++(++++)>$
L++++(+++) E W++(+) N+++(++) o? K? w--- O? M++ V? PS+() PE+(-) Y+
PGP+++ t+(+++) 5 X R? tv-(--) b++++(++) DI+ D+ G e->++++$ h!*()>++$ r
!y?(-)
- ------END GEEK CODE BLOCK------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)
iD8DBQFAIYW4ag7LSGnFq10RAiWSAJ4pBWm1zUPdbMQJHsaigGOaLZwz7gCfTz5M
YauQG1+GMvT0SmE0kcxib1I=
=bVbF
-----END PGP SIGNATURE-----
_______________________________________________
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.