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
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
No, you don't need to release strings created with @""
. You only need to release objects created with alloc
, retain
, copy
or new
.
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.
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.