我是 Objective-C 的新手,我不确定我是否以正确的方式使用 NSAutoreleasePool。
如果我只想使用一次自动释放,我使用:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *newText = [NSString stringWithFormat:@"%d", prograssAsInt]; sliderLabel.text = newText; [pool release]; //newText will be released
如果我想多次使用自动释放,我使用:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSString *newText = [NSString stringWithFormat:@"%d", prograssAsInt]; sliderLabel.text = newText; [pool drain]; //newText will be released newText = [NSString stringWithFormat:@"%d", prograssAsInt]; sliderLabel.text = newText; [pool drain]; //newText will be released newText = [NSString stringWithFormat:@"%d", prograssAsInt]; sliderLabel.text = newText; [pool release]; //newText will be released
这个可以吗?有内存泄漏吗?