views:

57

answers:

2

Am I responsible for releasing this string, and is it autorelease by default?

// command is of type NSData*
char cAddress[12];
[command getBytes:cAddress range:NSMakeRange(5,12)];
NSString *someString = [NSString stringWithCharacters:(const unichar*)cAddress length:12];
+2  A: 

Autoreleased by default.

kubi
A: 

It's autoreleased by default. Retained objects are usually created with methods in the form of:

[[MyClass alloc] ...]
[MyClass new] 
[object copy]
Diederik Hoogenboom
Or any method that *contains* alloc/new/copy. Please, please read the Memory Management Programming Guide (http://developer.apple.com/mac/library/documentation/cocoa/conceptual/MemoryMgmt/MemoryMgmt.html). It is the one true memory reference for Cocoa memory management.
Barry Wark
I agree. Really important document.
Diederik Hoogenboom