tags:

views:

38

answers:

2

For example, I need to append a word to an existing string.

NSString * temp = @"some prefix";
someString = [temp stringByAppendString: someString];

Should I release the object temp?

+3  A: 

You did not call any methods containing new, alloc, retain or copy, so you do not own it, so you should not release it.

Chuck
A: 

No, you shouldn't as you didn't increase retain count of @"some text".

PS: Actually, all @"..." constants have retainCount on MAX_INT, so it doesn't matter if you release them or not :).

kovpas
Means all @"..." are stored in a pool as constants? So what happened in my case? The string "some prefix" will be crated and stored in the pool? Then how to release it since it is no use now.
icespace
@icespace: "It is of no use now" does not mean you should release an object. You release objects only if you own them, and you do not own this one. In practice, it's stored in the data segment.
Chuck