在这里,我在“test”方法中使用了“tempString”的自动释放。根据规则,我应该在 main 中使用“[temp retain]”。但我没有使用它。它仍然可以正常工作并打印输出。那么“留”的需要是什么?谁能告诉我原因?提前致谢。
-(NSMutableString *) test : (NSMutableString *) aString{
NSMutableString *tempString=[NSMutableString stringWithString:aString];
[tempString appendString:@" World"];
return tempString;}
int main (){
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
MemoryMgmt *memoryMgmt=[[MemoryMgmt alloc] init ];
NSMutableString *str1 =@"Hello";
NSMutableString *temp = [memoryMgmt test: str1];
NSLog(@" %@",temp);
[pool drain];
return 0;
}