我刚刚用xcode创建了一个“单视图应用程序”,并在"viewDidLoad“方法中添加了一个UITapGestureRecognizer。然后,我使用仪器监控内存分配,每次我点击时,分配的内存大小都会增加。如果尝试多次点击,内存使用率会增加。为什么会有这样的行为?
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
[self.view addGestureRecognizer:tapGesture];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)handleTap:(UIGestureRecognizer *) sender
{
// NSLog(@"....");
}发布于 2013-05-24 20:41:59
我不确定这一点,但我认为这是因为系统的内存是动态分配的,所以当它意识到需要更多内存来处理按钮操作时,它将使用更多内存
https://stackoverflow.com/questions/16734973
复制相似问题