On Sep 16, 2008, at 7:41 PM, 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.

As far as the caller of -release is concerned, that is guaranteed to release the string *right now*. I.e. the retain implied by +alloc will be released.

That is all that it guarantees.

The pattern you describe would be an internal implementation detail. An odd one, at that. But nothing you, the caller, can really do anything about safely and without breaking encapsulation.

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.

No more so than -release. All -autorelease does is add the object to the NSAutoreleasePool, which will send -release when it is -drain'ed. If the instance does something goofy internally or, in the more common case, if something else holds a -retain, the object will not be deallocated upon -drain of the autorelease pool.

b.bum

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