本文介绍了为什么retainCount = 2 - 发布后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用此代码。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    view = [[UIView alloc] init];

    [_window addSubview:view];

    [view release];

    NSLog(@"count - %d", [view retainCount]);

    [self.window makeKeyAndVisible];

    return YES;

}


- (IBAction)click{

    NSLog(@"count - %d", [view retainCount]); 

}

当我点击uibutton时 - 我的视图保留count = 2 。
为什么会发生这种情况?

When i click to uibutton - my view retain count = 2. Why is this happening?

推荐答案

不要依靠retainCount。启动仪器并查看是否有泄漏。 Apple不鼓励使用retainCount进行调试:

Please do not count on retainCount. Fire up Instruments and see if there is a leak. Apple discourages the use of retainCount for debugging purposes:

查看文档。阅读,以便更深入地了解保留计数。

Have a look at the NSObjectProtocol and the retainCount documentation. Read the Memory Management Programming Guide for a deeper understanding of retain counts.

这篇关于为什么retainCount = 2 - 发布后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 10:23