If I make an NSString using the code below, do I need to need to release someString?
NSString *someString = @"somestring";
If I make an NSString using the code below, do I need to need to release someString?
NSString *someString = @"somestring";
No, it's a compile time constant string object, so it doesn't need releasing. It's the moral equiv of char *c = "hello world" -- where the string hello world is in global data, and you're assigning the address of this data to the pointer c.
No, since it's a compile-time constant string, you do not need to release it. In fact, doing so will likely cause a run-time error.
So, please check what Apple does under the section "Insert Data Using a POST Request" at the following link: http://developer.apple.com/safari/articles/creatingrestfulclients.html
I see a "[urlString release];", why?
thanks
incredible, they doesn't even try the code inside their articles oO. Thank you!
I checked
http://developer.apple.com/safari/articles/creatingrestfulclients.html
this case is different from NSString *someThing = @"someThing";
they should release urlString because of
[[NSString alloc] initWithFormat:@"%@%@", baseURLString, queryTerm];
Anywhere you use alloc/init you release it no mater what.
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.
Because constant NSString does not get released, would it cause memory problems if used extensively?