| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
On Sep 30, 2003, at 6:29 PM, Joseph Jones wrote:
Interesting. I thought convenience methods like mutableCopy gave you an already autoreleased object! I also thought that collections cleaned up their retained objects when they release. Is this not correct?
Nope.
Anything you +alloc, +allocWithZone:, -copy, -copyWithZone:, -mutableCopy, or -mutableCopyWithZone: returns a NEW object with a retain count of 1. Adding it to a collection which retains it bumps that to 2, and if you lose a reference to it, when the collection releases it (upon removal), it will leak. Any objects that are returned to you by calling methods should be autoreleased, and/or are owned by the receiver, so if you need to keep a reference to it yourself, you retain it and assign it to a pointer (id). You still don't own it, but if the actual owner (which created the object) releases it, whenever you release it, then it might be dealloc'ed.
Better revise your code ASAP... ;)
--
Shaun Wexler
MacFOH
http://www.macfoh.com
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.