使用Macaw依赖项的事件处理程序时发生内存泄漏

时间:2019-05-31 18:31:29

标签: ios swift memory-leaks

我创建了一个演示应用程序,以尝试使用矩形节点上的onPan和onPinch事件拖动和缩放形状。我正在使用Macaw图形库。该应用在滚动视图中具有较大的背景图像,而金刚鹦鹉视图的大小与图像视图相同。我想在图像上创建一个矩形形状,并能够对其进行拖动并调整其大小,但每次激活事件时,我都会发现一些内存泄漏,一段时间后会导致应用崩溃。

我将应用程序缩小为以下几行,并且它仍然保留内存,尽管更少。我正在使用0.9.5版。可能是什么原因?内存泄漏正常吗?

import UIKit
import Macaw

class ViewController: UIViewController {

    var macawView = MacawView()

    let stroke = Stroke(fill: Color.red, width: 1.0)
    var group: Group!
    override func viewDidLoad() {
        super.viewDidLoad()
        configMacawView()

        let square = Shape(form: Rect(x: 0, y: 0, w: 80.0, h: 120.0), fill: Color.clear, stroke: stroke)

        square.onPan { event in
            square.place = square.place.move(dx: event.dx, dy: event.dy)
        }

        macawView.node = square

    }

    func configMacawView(){
        let imageView = UIImageView()
        let image = #imageLiteral(resourceName: "Medical_X-Ray_imaging_AAR02_nevit")
        imageView.image = image
        imageView.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(imageView)

        imageView.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
        imageView.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true
        imageView.widthAnchor.constraint(equalTo:view.widthAnchor).isActive = true
        imageView.heightAnchor.constraint(equalTo:view.heightAnchor).isActive = true

        macawView.backgroundColor = .clear
        macawView.translatesAutoresizingMaskIntoConstraints = false
        self.view.addSubview(macawView)

        macawView.centerXAnchor.constraint(equalTo: imageView.centerXAnchor).isActive = true
        macawView.centerYAnchor.constraint(equalTo: imageView.centerYAnchor).isActive = true
        macawView.widthAnchor.constraint(equalTo:imageView.widthAnchor).isActive = true
        macawView.heightAnchor.constraint(equalTo:imageView.heightAnchor).isActive = true
    }
}

0 个答案:

没有答案