Created
April 11, 2012 07:32
-
-
Save taka328w/2357589 to your computer and use it in GitHub Desktop.
メモリ管理(Non ARC)
This file contains 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
1. initXXXメソッドは呼び出し側がrelease/autoreleaseする | |
2. 1以外のメソッドはメソッド側でautoreleaseした変数を返す | |
=> frameworkもこの原則を守っている | |
3. retain/copyした変数は、retain/copyした側が責任を持ってreleaseする | |
4. NSMutableArrayなどにaddObjectした変数はaddObject後にrelease可能 | |
=> autorelease済みならばreleaseしてはダメ | |
5. クラスのプロパティへの代入はautorelease or releaseする | |
=> 1の原則から考えると当たり前 | |
◯ | |
object.text = [[[NSString alloc] initWithString:@"string"] autorelease]; | |
◯ | |
NSString *string [[NSString alloc] initWithString:@"string"]; | |
object.text = string; | |
[string release]; string = nil; | |
☓ | |
object.text = [[NSString alloc] initWithString:@"string"]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment