上QQ阅读APP看书,第一时间看更新
Using and misusing manual reference counting
Now, let's take a look at how we can use and abuse those mechanics, and the kinds of errors that we can litter our code with when using manual reference counting:
- (void) doSomething {
NSString *aString = [[NSString alloc] init];
// calling alloc returns an object with a retain count of 1
// do something with the string
// We're done with the string, call release
[aString release];
}
The preceding is a very simplistic example; many times, you'll pass your objects around, and will need to keep track of when to retain or release your objects. Let's go over some of the issues that you can encounter if you're not careful with your retain and release calls.