這裏我在'test'方法中使用了'tempString'的自動釋放。根據規則,我應該在主體中使用「[temp retention]」。但我沒有使用它。它仍然可以正常工作並打印輸出。那麼「保留」的需求是什麼?任何人都可以告訴我原因嗎?提前致謝。爲什麼它沒有'保留'的對象工作正常?
-(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 [email protected]"Hello";
NSMutableString *temp = [memoryMgmt test: str1];
NSLog(@" %@",temp);
[pool drain];
return 0;
}