以下の挙動を確認しました。
2 つのプロパティ変数を取ります。
@property (nonatomic, retain) NSString *stringOne;
@property (nonatomic, assign) NSString *stringTwo;
コードの下に記述された.mファイルで..
NSMutableString *localstring= [[NSMutableString alloc] initWithString:@"test"];
self.stringOne = localstring;
NSLog(@"localstring = %d", [string retainCount]);
NSLog(@"string one retain count = %d", [self.stringOne retainCount]);
self.stringTwo = localstring;
NSLog(@"localstring = %d", [localstring retainCount]);
NSLog(@"string two retain count = %d", [self.stringTwo retainCount]);
ここでは、alloc のため、localstring 保持カウントは 1 です。今、私はself.stringOne = localStringを与えました。
stringOneのretainプロパティにより、localstringのretain回数は2回になります。今、私はself.stringTwo = localStringを与えました。
ここでも、localstring の保持カウントが 1 つ増えます。stringTwo に assign プロパティを指定したことに注意してください。実際には、localstring または stringTwo の保持カウントは、割り当てプロパティであるため、1 増加することはありません。私が間違っている場合は修正してください。
ありがとうジテン