Do I need to release a constant NSString?

前端 未结 2 2074
孤独总比滥情好
孤独总比滥情好 2020-12-17 04:46

I\'m reading memory management rules to this point where it said

- (void)printHello {

    NSString *string;

    string = [[NSString alloc] initWithString:@         


        
2条回答
  •  我在风中等你
    2020-12-17 05:05

    Bavarious's answer is correct. For the curious, I can add that this is documented in Apple's “String Programming Guide”, specifically the section “Creating Strings” where it says (emphasis mine):

    The simplest way to create a string object in source code is to use the Objective-C @"..." construct:

    NSString *temp = @"/tmp/scratch";

    Note that, when creating a string constant in this fashion, you should use UTF-8 characters. Such an object is created at compile time and exists throughout your program’s execution. The compiler makes such object constants unique on a per-module basis, and they’re never deallocated.

提交回复
热议问题