Do I need to release a constant NSString?

前端 未结 2 2060
孤独总比滥情好
孤独总比滥情好 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:10

    @"…" is a literal instance of NSString. When the compiler sees a literal string, it maps the string into the binary file (e.g. your program) and the string is available as an NSString object when the binary is loaded (e.g. when you run your program). You don’t have to manage the memory occupied by literal strings because they’re an intrinsic part of your binary — they are always available, they never get released, and you don’t have to worry about managing their memory.

提交回复
热议问题