我新的Objective-C和我不知道如果我使用NSAutoreleasePool的正确途径。这是使用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
这是好?有没有内存泄漏?
我觉得无礼是没有道理的。虽然这是记录在案,这是非常违反直觉的,到了那里我从有经验的程序员可可究竟是谁阅读文档,并没有认为它的意思是说,听到了点。我不认为对于刚接触这个框架的人来说这是一个不合理的问题。 – Chuck