exyte / Macaw

Powerful and easy-to-use vector graphics Swift library with SVG support
MIT License
6.02k stars 556 forks source link

SVGParser.parse() memory leak #663

Closed abe-union closed 4 years ago

abe-union commented 4 years ago

I am displaying a floor plan which is always the same. Everytime I make a change I just parse the same floor view svg into a Group

floorLayout = try SVGParser.parse(text: floor.birdsEyeViewSvg) as? Group

and apply the proper styling as follows:

switch tag {
            case .background:
                guard let shape = node as? Shape else { continue }
                shape.fill = backgroundColor
                let borderWidth: Double = UIScreen.main.sizeType == .iPad1366 ? 1.5 : 2
                shape.stroke = Stroke(fill: stateColor, width: borderWidth)

            case .name:
                guard let text = node as? Text else { continue }
                if let tableOwner = tableOwner {
                    text.text = "\(text.text)\n\(tableOwner.initials)"
                    text.baseline = .alphabetic
                } else {
                    text.baseline = .mid
                }
                let fontSize = UIScreen.main.sizeType == .iPad1366 ? 8 : 10
                let systemFont = Font(name: "SF UI Display",
                                      size: fontSize,
                                      weight: "regular")
                text.font = systemFont
                text.fill = isNameHidden ? Color.clear : Color(val: UIColor.gray1Color().hex)
                text.align = .mid

            case .alert:
                guard let image = node as? Image else { continue }
                image.src = isAlertHidden ? "hidden" : "icon.alert.red"

}

and then I set to MacawView.node. However when we set a new node, we don't see memory getting release. Inside the profiler I found an extended amount of memory leaks, which I have taken screenshots off.

Memory leak 2 2020-01-16 at 5 06 24 PM Memory leak 2020-01-16 at 5 04 31 PM Macaw Group 2020-01-14 at 10 20 42 AM

abe-union commented 4 years ago

Strong reference cycle created in our side. Memory leak solved