gpt4 book ai didi

ios - 为什么 retainCount = 2 - 发布后?

转载 作者:行者123 更新时间:2023-11-28 18:14:33 26 4
gpt4 key购买 nike

我使用这个代码。

- (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 - 我的 View 保留计数 = 2。为什么会这样?

最佳答案

不要依赖于 retainCount。启动仪器,看看是否有泄漏。 Apple 不鼓励将 retainCount 用于调试目的:

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 and the retainCount文档。阅读 Memory Management Programming Guide以便更深入地了解保留计数。

关于ios - 为什么 retainCount = 2 - 发布后?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6276442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com