1

How do we release NSString that is not alloc or evern other objects?

Example:

NSString *test = @"testing";

Thanks for your help.

Dilip Manek
  • 9,095
  • 5
  • 44
  • 56
iosdevnyc
  • 1,873
  • 5
  • 25
  • 48
  • This is somewhat a duplicate of http://stackoverflow.com/questions/6069459/does-some-text-give-an-autoreleased-or-retain-1-object-back – axiixc Jun 15 '11 at 02:57

1 Answers1

11

You don't. You just release the objects you own. You own the object if you used alloc, copy or new keywords when instantiating them.

Desdenova
  • 5,326
  • 8
  • 37
  • 45
  • Why would I need to alloc an object ? – iosdevnyc Jun 15 '11 at 02:35
  • @iosdevnyc - There are some initializer methods that don't have corresponding "convenience" creation methods. Aside from that, it's mostly a matter of using whichever style is a better fit for the ownership pattern you need. If you're going to assign the object to a retained property, for example, the property accessor will establish the ownership claim, so using a convenience constructor is easier than an alloc/init/assign/release series. – Sherm Pendley Jun 15 '11 at 03:07
  • `NSString *howOld = [[NSString alloc] initWithFormat:@"I am %d years old", myAge];` - string values known at compile time are not alloc'd, those you create programmatically are – bshirley Jun 15 '11 at 03:35