Objective c 删除UIImageView并取回内存(我的内存正在泄漏)

Objective c 删除UIImageView并取回内存(我的内存正在泄漏),objective-c,memory,uiimageview,erase,Objective C,Memory,Uiimageview,Erase,我正在制作一个简单的绘图应用程序,但a内存有问题。使用几分钟后,它就崩溃了,这使得iPad速度非常慢 用户创建图形的线条由2x2像素的UIImageView组成,因此,此UIImageView被创建了几次: UIImageView*dibujo = [[UIImageView alloc] initWithFrame:CGRectMake(x-1,y-1,2,2)]; dibujo.image = [UIImage imageNamed:@"pixelde2po2.png"]; tagdedib

我正在制作一个简单的绘图应用程序,但a内存有问题。使用几分钟后,它就崩溃了,这使得iPad速度非常慢

用户创建图形的线条由2x2像素的UIImageView组成,因此,此UIImageView被创建了几次:

UIImageView*dibujo = [[UIImageView alloc] initWithFrame:CGRectMake(x-1,y-1,2,2)];
dibujo.image = [UIImage imageNamed:@"pixelde2po2.png"];
tagdedibujo=tagdedibujo+1;
dibujo.tag=tagdedibujo;
[self.view addSubview:dibujo];
它是这样被擦除的:

    for (int aa=ultimotag+1; aa<=tagdedibujo; aa++) {
    //NSLog(@"destruyendo: %i", aa);
    UIImageView*dibujo1 = (UIImageView *)[self.view viewWithTag:aa];

    [UIView animateWithDuration:0.5 animations:^{
        dibujo1.alpha=0;
    }];

}

[self performSelector:@selector(matardibujo) withObject:(self) afterDelay:(0.51)];
   ultimotag=tagdedibujo;




-(void) matardibujo{
for (int aa=ultimotag+1; aa<=tagdedibujo; aa++) {
    [[self.view viewWithTag:aa] removeFromSuperview];
}

for(int aa=ultimotag+1;aa能否用以下代码行替换
dibujo.image=[UIImage imageNamed:@“pixelde2po2.png”];
以查看它是否解决了您的问题

NSString *fileName = [[NSBundle mainBundle] pathForResource:@"pixelde2po2" ofType:@"png"];
UIImage *image = [UIImage imageWithContentsOfFile:fileName];

如果不使用ARC,请在
[self.view addSubview:dibujo];
插入
[dibujo release]
我禁用了ARC来尝试此操作,但没有任何效果,它的作用是相同的。擦除绘图后,内存使用率甚至比擦除之前更高。是否确实已从superview中正确删除视图?我发现执行选择器的延迟为0.51,对于简单的视图删除应该可以(您必须等待动画完成后才能删除视图,并且动画时间为0.50)…但是对于一个循环中一个接一个地设置动画的更多视图来说,这是否足够?您在该循环中设置了多少视图的动画?请尝试增加延迟,或者更好地使用[UIView animateWithDuration:animations:completion:](在完成中,仅在最后一个动画上调用主线程上的performselector)或尝试完全删除performselector并使用以下命令更改UIView动画行:
[UIView animateWithDuration:0.5 animations:^{dibujo1.alpha=0;}完成:^{[dibujo1 removeFromSuperview];}]
您是对的,没有正确删除视图。问题是,当您尝试在第二条注释中所写的内容时,会出现以下错误:不兼容的块指针类型将'void(^)(void)'发送到参数'void(^)(bool)