Do I need to release NSString generated using @“…”?

前端 未结 6 600
既然无缘
既然无缘 2020-12-03 10:52

If I make an NSString using the code below, do I need to need to release someString?

NSString *someString = @\"somestring\";
6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 11:22

    If you created an object via a method call that contains alloc, retain, or copy, or starts with new (N-A-R-C = "narc"), then you are responsible for releasing the object. If this is not the case, then you can ignore the object.

    So in the case of strings:

    NSString * myString = @"This is a string";
    

    I don't see a call there to a NARC method, so you are not responsible for releasing it. It's really that simple.

提交回复
热议问题