Skip to content

Instantly share code, notes, and snippets.

@jazzsasori
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jazzsasori/8895113 to your computer and use it in GitHub Desktop.
Save jazzsasori/8895113 to your computer and use it in GitHub Desktop.
weak strongテスト
// 以下は同義
// __strong NSString *strongString;
// NSString *strongString;
__strong NSString *strongString = [[NSString alloc] initWithFormat:@"テスト"];
__weak NSString *weakString = strongString;
NSLog(@"strong: %@ , weak: %@", strongString, weakString); // strong: テスト , weak: テスト
// 「テスト」が解放される
strongString = [[NSString alloc] initWithFormat:@"あいう"];
NSLog(@"strong: %@ , weak: %@", strongString, weakString); // strong: あいう , weak: nil
__weak NSString *weakString2 = [[NSString alloc] initWithFormat:@"あいう"];
NSLog(@"%@", weakString2); // 代入した瞬間に解放されるので、nilが出力される
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment