简体   繁体   English

存储在“测试”中的对象的潜在泄漏

[英]Potential leak of an object stored into “test”

I am working on an app in Xcode and I need some help. 我正在使用Xcode开发应用程序,需要一些帮助。

- (IBAction)test:(id)sender {
    game *test = [[game alloc] initWithNibName: nil bundle: nil];

    [self presentViewController:test animated:YES completion:nil];
}    

I am getting the following error and I don't know how to fix it. 我收到以下错误,但我不知道如何解决。

Potential leak of an object stored into "test" 存储在“测试”中的对象的潜在泄漏

If not using ARC, you should autorelease your object: 如果不使用ARC,则应autorelease对象:

game *test = [[[game alloc] initWithNibName: nil bundle: nil] autorelease];

When you present the controller, it will be retained for you, but when you dismiss it, it will automatically be released for you. 当您提供控制器时,它将为您保留,但是当您关闭它时,它将为您自动释放。 Your current code will probably result in a leak (unless you manually release elsewhere). 您当前的代码可能会导致泄漏(除非您在其他地方手动release )。 Using autorelease (or explicitly release after presentViewController ) will prevent both the warning as well as the leak. 使用autorelease (或在presentViewController之后显式release )将防止警告和泄漏。

if you are not used the ARC, so you can need to autorelease the objcet. 如果不使用ARC,则需要autorelease objcet。

when you are making the objcet then it's reatin count get be increment by 1. but after your work is done your retain count not being decreases that's why this error (leak) happen. 当您制作objcet时,其reatin count将增加1。但是在完成工作后,保留计数不会减少,这就是发生此错误(泄漏)的原因。 so if you you used the autorelease then autorelease pool manage your retain count after dismiss the viewcontroller decreases the retain count . 因此,如果您使用了自动释放,则autorelease pool在关闭视图控制器后减少retain count从而管理您的retain count

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM