为什么retainCount = 2 - 发布后? [英] Why retainCount = 2 - after release?

查看:101
本文介绍了为什么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:


重要:此方法通常为
没有调试内存的价值
管理问题。因为任何数量
的框架对象可能保留了
一个对象,以便保存对它的引用
,同时
自动释放池可能持有任何

对象的延期发布数量,你不太可能从
方法中获得有用的信息。

Important: This method is typically of no value in debugging memory management issues. Because any number of framework objects may have retained an object in order to hold references to it, while at the same time autorelease pools may be holding any number of deferred releases on an object, it is very unlikely that you can get useful information from this method.

查看 NSObjectProtocol和retainCount 文档。阅读内存管理编程指南,以便更深入地了解保留计数。

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 - 发布后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆