Suppose I get a string C from some function:
char * mystring = SomeCFunction(...);
And I have this line (I am responsible for releasing it when I finished).
If in Objective-C I create an NSString * using:
NSString * mynsstring = [NSString stringWithCString:mystring encoding:NSUTF8StringEncoding];
Am I still responsible for freeing the original C line?
I suppose the answer is yes, but I cannot find the final answer in the documentation - and the functionality of the opposite method ( cStringUsingEncoding ), while sensitive, pauses because it processes cString frees you up.
If the answer is yes, am I also responsible for not releasing the string c before I finish using NSString * , or does the function copy the string for me? I ask for this because the documentation for stringWithCString says:
Returns a string containing bytes in the given array C, is interpreted according to the specified encoding.
Which still leaves me wondering if he really copied bytes or just points to them internally (and I'm just doing actors).
Steve source share