A philosophical question, of sorts. Is it proper to assign a constant string to an @property that's (retained)? Or, should I do self.string = [NSString stringWithString:@""]
;
Is there a memory leak? What if it's overre开发者_Python百科leased?
It's a constant string, so does it behave the same way as an NSString object?
If the property is (assign) does that mean it will not be valid after the run loop?
Yes, it's fine. No matter which way you do it, the constant string will still be compiled into your program (because you have to use it in [NSString stringWithString:@""]
anyway). Constant strings don't actually get retained/released, but the what matters is the semantics of it: you're assigning a string (which has a net +0 retainCount as far as you're concerned — you haven't alloc
ed it, so you don't own it) to a property which will take ownership of it. If the property is (assign)
, then it may still work with a constant string, but it will be semantically invalid after the autorelease pool drains.
精彩评论