Iphone 对象泄漏:以后未引用分配的对象

Iphone 对象泄漏:以后未引用分配的对象,iphone,Iphone,当我分析它时,得到以下信息: 方法为下面的语句返回一个Objective-C对象,其保留计数为+1 self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 此执行路径中稍后不会引用已定位对象的对象,其保留计数为+1 [self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)

当我分析它时,得到以下信息:

方法为下面的语句返回一个Objective-C对象,其保留计数为+1

self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
此执行路径中稍后不会引用已定位对象的对象,其保留计数为+1

[self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
任何人都知道如何修复这些消息


谢谢您的帮助。

self.view是一个@属性,设置后将保留该属性。你需要释放它

尝试:


self.view是设置时保留的@属性。你需要释放它

尝试:


假设
view
是具有
retain
属性
self的属性。view
保留视图,因此由
initWithFrame
创建的retain是需要释放的附加retain

简单的自动释放:

UIView *newView = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

如果可能的话,最好使用ARC。ARC可用于iOS 4.x及更高版本,并以文件为基础提供混合实现。然后,应用程序中没有
retain
release
autorelease
调用。

假设
view
是一个具有
retain
属性
self的属性。view
保留视图,因此
initWithFrame
创建的retain是需要释放的附加retain

简单的自动释放:

UIView *newView = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

如果可能的话,最好使用ARC。ARC可用于iOS 4.x及更高版本,并以文件为基础提供混合实现。然后,应用程序中没有
retain
release
autorelease
调用。

您是否尝试过用发布平衡视图的alloc?是否尝试过用发布平衡视图的alloc?
UIView *newView = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];