[英]Potential leak of an object stored into “test”
我正在使用Xcode開發應用程序,需要一些幫助。
- (IBAction)test:(id)sender {
game *test = [[game alloc] initWithNibName: nil bundle: nil];
[self presentViewController:test animated:YES completion:nil];
}
我收到以下錯誤,但我不知道如何解決。
存儲在“測試”中的對象的潛在泄漏
如果不使用ARC,則應autorelease
對象:
game *test = [[[game alloc] initWithNibName: nil bundle: nil] autorelease];
當您提供控制器時,它將為您保留,但是當您關閉它時,它將為您自動釋放。 您當前的代碼可能會導致泄漏(除非您在其他地方手動release
)。 使用autorelease
(或在presentViewController
之后顯式release
)將防止警告和泄漏。
如果不使用ARC,則需要autorelease
objcet。
當您制作objcet時,其reatin count
將增加1。但是在完成工作后,保留計數不會減少,這就是發生此錯誤(泄漏)的原因。 因此,如果您使用了自動釋放,則autorelease pool
在關閉視圖控制器后減少retain count
從而管理您的retain count
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.