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 Leaks in subclass of LineChartView #3813

Closed
liufannnn opened this issue Jan 11, 2019 · 2 comments
Closed

Memory Leaks in subclass of LineChartView #3813

liufannnn opened this issue Jan 11, 2019 · 2 comments

Comments

@liufannnn
Copy link

class MyLineView: LineChartView {
    var xAxisMaximum = 0 {
        didSet {
            if xAxisMaximum > 0 {
                xAxis.axisMaximum = Double(xAxisMaximum)
                xAxis.labelCount = xAxisMaximum
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    deinit {
        DZPrint("++")
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }

    func setData() {
        let entryArr = (0...24).map { ChartDataEntry(x: Double($0), y: 100) }
        let dataSet = LineChartDataSet(values: entryArr, label: title)
        // leaks here
        data = LineChartData(dataSet: dataSet)
    }

    private func setupUI() {
        dragEnabled = false
        scaleYEnabled = false 
        scaleXEnabled = false
        doubleTapToZoomEnabled = false
        dragDecelerationEnabled = false 
    }
}

In my project, my viewController has called deinit, but MyLineView not called deinit when called MyLineView.setData()

Charts Environment

**Charts version/Branch/Commit Number:3.2.1
**Xcode version:10.1
**Swift version:4.2
**Platform(s) running Charts:iOS
**macOS version running Xcode:macOS Mojave 10.14.2

@liuxuan30
Copy link
Member

liuxuan30 commented Jan 14, 2019

you have to let Xcode or instruments point out which one is not being released.
a classic mistake is you use a wrong valueFormatter delegate to cause a retain cycle.
Reopen when you have more details.

@liufannnn
Copy link
Author

liufannnn commented Jan 24, 2019

Add myLineView.renderer = nil in my viewController deinit, It solved the problem.

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

2 participants