Re: Memory management question
Re: Memory management question
- Subject: Re: Memory management question
- From: Shawn Erickson <email@hidden>
- Date: Wed, 24 Mar 2004 15:52:33 -0800
On Mar 24, 2004, at 11:14 AM, Alastair Houghton wrote:
Alternatively, you can
immediately release any individual autoreleased object by doing
[[someObject retain] release];
(The -retain increments the reference count, removing it from the
autorelease pool, then the -release triggers the deallocation of the
object.)
Outlining what you said in the above...
1) allocated -> retain count = 1
2) autorelease -> retain count = 1 (the release is pending)
3a) retain -> retain count = 2
3b) retain -> remove object from autorelease pool (pending release is
canceled)
4) release -> retain count = 1
If it does exactly what you say in the above then you are left with an
object that will leak since it has an unbalanced retain.
Did you mean instead something like the following...
1) allocated -> retain count = 1
2) autorelease -> retain count = 1 (the release is pending)
3) retain -> remove object from autorelease pool (one instance of it in
the pool)
4) release -> retain count = 0
5) dealloc
...or what more likely really happens...
1) allocated -> retain count = 1
2) autorelease -> retain count = 1 (the release is pending)
3) retain -> retain count = 2
4) release -> retain count = 1
5) release -> retain count = 0 (release sent by autorelease pool)
6) dealloc
-Shawn
_______________________________________________
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.