【发布时间】:2011-05-14 18:43:27
【问题描述】:
我刚刚在我的项目上运行了 clang 静态分析器,我收到以下警告:
Incorrect decrement of the reference count of an object that is not owned at this point by the caller
请你告诉我我的问题是什么。我通常能够很好地管理我的应用程序中使用的内存。
self.cupboardViewController = [[CupboardViewController alloc] initWithNibName:@"CupboardViewController" bundle:[NSBundle mainBundle]];
[self.window addSubview:self.cupboardViewController.view];
- (void)dealloc {
[[self cupboardViewController] release];//where I am getting the warning.
[super dealloc];
}
【问题讨论】:
-
假设
cupboardViewController被标记为retain,无论如何你都会泄漏它,因为它会自动保留你在示例的第一行中创建的新对象。您应该在将其分配给属性之前自动释放该对象,à laself.cupboardViewController = [[[CupboardViewController alloc] init...] autorelease];。 -
我这样做了,但它导致应用程序在一段时间后崩溃。
标签: iphone objective-c cocoa-touch memory-management