emailconfirmed, nsInternRO, nsInternRW, Administrators
3,356
edits
| m (→Retain-Count) | |||
| Line 16: | Line 16: | ||
| * alloc (owner) | * alloc (owner) | ||
| * copy (owner) | * copy (owner) | ||
| * new (owner, selten) | * new (owner, selten verwendet) | ||
| * retain | * retain | ||
| Autorelease erhöht zwar den retain-count ebenfalls +1, in der nächsten Runloop wird der retain-count allerdings automatisch um −1 verringert. Deshalb ist hierfür kein release mehr erforderlich. | Autorelease erhöht zwar den retain-count ebenfalls +1, in der nächsten Runloop wird der retain-count allerdings automatisch um −1 verringert. Deshalb ist hierfür kein release mehr erforderlich. | ||
| ===Beispiel=== | |||
| Rechenbeispiel zum retain-count (kein wirklich sinnvolles Code-Beispiel!) | |||
| <source lang="objc"> | |||
| NSString *myObj; // retaincount: 0 | |||
| myObj = [[NSString alloc] initWithString:@"hello"]; // retaincount: 1 | |||
|     [myObj retain]; // retaincount: 2 | |||
|     [myObj release]; // retaincount: 1 | |||
|     NSString *newString = [myObj copy]; // retaincount myObj: unverändert (1), newString: 1 | |||
|     [newString autorelease]; // retaincount: 1; next loop retaincount: 0 | |||
| [myObj release]; // retaincount: 0 | |||
| </source> | |||
| == Alloc/Init/Copy/Retain == | == Alloc/Init/Copy/Retain == | ||