我有這樣的情況:類的方法和「上線分配對象的潛在泄漏......」
- (void) foo {
NSLog(@"Print this: %@", [MyObject classString]);
}
// So in MyObject.m I do
@implementation MyObject
+ (NSString *) classString {
return [OtherObject otherClassString]; //The Warning "Potential leak..." is for this line
}
@end
// Finally in OtherObject
@implementation OtherObject
+ (NSString *) otherClassString {
NSString *result = [[NSString alloc] initWithString:@"Hello World"];
return result;
}
@end
在開始的時候,我有一個預警otherClassString
和classString
但這種方式對於otherClassString
這項工作。
現在我的問題是在的classString
。我嘗試了很多東西,但始終顯示此警告。我不能在類方法中調用類方法嗎?
大聲笑,解決方案是把autorelease在2函數中。你的規則工作! – Rodrigo