On Sep 16, 2008, at 22:41 , Roland King wrote:

Jason Coco wrote:


NSMutableString *str = [[NSMutableString alloc] initWithCapacity:someAssumedCapacity];
/* do stuff */
[str release];

Is that actually guaranteed to release the string *right now*? I only ask because I seem to recall a message a couple of months ago about a more complicated object where it appeared that the initializer did a retain/autorelease on the object so it ended up in the autorelease pool before you even got hold of it. That was not an object obtained from a convenience method either IIRC, it was a [ [ SomeClass alloc ] initConstructorOfSomeSort ] call.

Unlikely the case with NSMutableString I'd think, but perhaps for other things.

The local autorelease pool version I'd think is guaranteed to work.

It's guaranteed to release the string *right now*, but that doesn't mean that the string will be deallocated *right now*. Like the case you stated above, other "owners" may also have bumped up the retain count. It will be deallocated whenever the retain count reaches 0. For instance, if you add the NSMutableString to an NSArray, the NSArray is going to retain it, so the memory will not be deallocated until you remove it from the array, or the array gets deallocated.

Basically all it guarantees is that *you* don't own this NSMutableString (or whatever object) anymore.

/jason

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to