Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak when using Event handlers #597

Closed
georgepedrosa opened this issue May 31, 2019 · 1 comment
Closed

Memory leak when using Event handlers #597

georgepedrosa opened this issue May 31, 2019 · 1 comment
Assignees
Milestone

Comments

@georgepedrosa
Copy link

I created a demo app to try to drag and scale shapes using onPan and onPinch events on a rectangle Node. The app has a large background image inside a scroll view, and the macaw view has the same size as the image view. I want to create a rectangle shape over the image, and be able to drag and resize it, but I noticed some memory leak every time I activate an event, crashing the app after some time. I downsized the application to the following lines and it's still retaining memory, though much less. I'm using version 0.9.5. What could be the cause? Is the memory leak normal?

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
    }
}
@mnndnl mnndnl self-assigned this Jun 3, 2019
@ystrot ystrot added this to the 0.9.6 milestone Jun 3, 2019
@ystrot ystrot closed this as completed in 34292e6 Jun 3, 2019
ystrot added a commit that referenced this issue Jun 3, 2019
Fix #597: Memory leak, close graphics context in doFindNode method
@ystrot
Copy link
Member

ystrot commented Jun 3, 2019

Hi @georgepedrosa,

Thanks for reporting! The fix available in the master branch and will be part of the next release.

@ystrot ystrot modified the milestones: 0.9.6, 0.9.7 Apr 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants