ios - 我的油漆泄漏内存?

标签 ios cocoa-touch memory-management

我找到了这个 paint app并在其上使用了 Profile/Zombie 工具。显然,当您绘制时,内存会不断增加。

我想我找到了它泄漏的地方,但我无法弄清楚它到底出了什么问题。

有什么想法吗?这是问题代码:

 - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    mouseSwiped = YES;

    UITouch *touch = [touches anyObject];   
    CGPoint currentPoint = [touch locationInView:self.view];
    currentPoint.y -= 0;


    UIGraphicsBeginImageContext(self.view.frame.size);
    [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 0.0, 0.0, 1.0);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    lastPoint = currentPoint;

}

最佳答案

您可能需要使用 Profile - Leaks 工具来检测泄漏。 Zombies instrument 通过为任何已释放的对象放置 NSZombie 对象来工作,这就是为什么您会看到已分配对象的数量持续增加的原因。

关于ios - 我的油漆泄漏内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8760747/

相关文章:

循环字符串数组中的C内存管理

ios - 如何使用 RLMArray 保存数组

ios - 从 Swift 中的 UIWindow 更改 UIViewController 中的 IBOutlet

ios - 使用另一行时模糊 UIPickerView 行之一

iphone - UIImagePickerController 相机预览在横向应用程序中是纵向的

android - 使用弱引用是避免内存泄漏的最佳方法吗?

objective-c - Hello World 应用程序

android - 单击 flutter 中的警报对话框时屏幕未关闭

iphone - Objective C 等同于 javascript setTimeout?

linux - 为什么内核映射到与进程相同的地址空间?