我正在尝试找出为什么在接口构建器中创建UIBUTTON时 - 通过Xcode运行仪器应用程序时会发生内存泄漏。

这就是我创建内存泄漏的方式。

我打开了一个新应用程序,打开了接口构建器中的myAppViewController.xib文件。我将背景更改为黑色。添加了一个Uibutton,将其重命名为“ Foo”标题。保存然后退出。

在myAppViewController.h文件中,我有以下内容

#import <UIKit/UIKit.h>

@interface miPlanNewViewController : UIViewController { 
    IBOutlet UIButton *tasksProjects; 
}
@property(nonatomic, retain) IBOutlet UIButton *tasksProjects;
@end

在myAppViewController.m文件中,我有以下内容:

#import "miPlanNewViewController.h"

@implementation miPlanNewViewController
@synthesize tasksProjects;

...
//the normal methods you get
...
- (void)dealloc {
    [super dealloc];
}
@end

这是我目前在乐器中获得的屏幕截图。

alt text alt text

我注意到的一件事...

我尚未将插座连接到Interface Builder中的Uibutton,但是当我从接口构建器中删除Uibutton时,保存,然后再次使用仪器运行程序时,我根本不会泄漏任何泄漏。

有人可以解释正在发生的事情以及如何解决这个问题。谢谢你。

有帮助吗?

解决方案

  • 首先,您不会发布该属性。在Dealloc中,您应该有[tasksProjects release]; 在ViewDidunload中,您应该有 self.taskProjects = nil;
  • 其次,当LXT量化时,您不应使用模拟器进行内存泄漏检查。
  • 第三,检查您是否正在构建发行版,而不是调试。
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top