0

How does a constant declared as below in the implementation part of a class is released:

static NSString *myconst = @"some data...";

Thx for helping,

Stephane

Stephane
  • 4,978
  • 9
  • 51
  • 86

3 Answers3

2

No, you don't need to release strings created with @"". You only need to release objects created with alloc, retain, copy or new.

Alex
  • 9,313
  • 1
  • 39
  • 44
1

You don't have to release it. The string literals reside in the executable's data section, not in the dynamically allocated memory (AKA heap).

There's no harm in accidentally calling release though. I'm pretty sure the literals are wired to quietly ignore that call.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
1

retain, release and autorelease messages to strings of the above kind are ignored.

Read Apple's memory management docs here

However one thing to note here is passing release crashes the app. Hence the usual idea being, if you haven't used alloc or retain on the string, don't attempt to release it.

Also read this useful link here which explains the same thing.

Bourne
  • 10,094
  • 5
  • 24
  • 51