Last active
August 29, 2015 13:56
-
-
Save jazzsasori/8895113 to your computer and use it in GitHub Desktop.
weak strongテスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 以下は同義 | |
// __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