Weight/second live chart memory overload

Hi all,

I'm trying to implement a dynamic chart to log weight over time for an espresso app. I've been struggling to find recourses to plot a continuously updating chart so, I'm currently using a timer to append new data to an array and then redraw the chart.

Thats all working fine but, I'm getting 1GB< Memory usage after appending only 15 seconds worth of data at 10 datapoints/second. I would love to find a way to optimise this.

Here is my main View Controller. There is some connect to scale stuff in there but, for testing I'm bypassing the scale data. All I'm doing is upon opening the view I'm: starting a counter, converting the counter to a min, sec ,millisec value, appending time information from my counter to the array, appending a random value from 1-10 as my mock weight data to the array, calling my chart view because it lives in a different file

import UIKit
import AcaiaSDK
import SwiftUI
import Charts

    var cList: [weight_time] = []
    var timer: Timer!
    var count: Double!
    var timeInDouble: Double!
    var isCounting: Bool!
    var hideview: Bool = true
    

class ChartVC: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()   
    }
    
    override func viewWillAppear(_ animated: Bool) {
    }
    
    override func viewDidAppear(_ animated: Bool) {
        timeInDouble = 0
        count = 0
        createTimer()
        print("Timer Started")
        isCounting = true
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        if isCounting == true {
            timer.invalidate()
            print("Timer Stopped")
            isCounting == false
        }
    }
 
    
    func createTimer(){
        cList.removeAll()
        timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(counter), userInfo: nil, repeats: true)
    }
    
    @objc func counter(){
       
        count += 0.1
        let minutes = Int(count) / 60 % 60
        let seconds = Int(count) % 60
        let mil = Int(count*10) % 10
        //print(mil)
        let m_s = String(format:"%02i.%02i%01i", minutes, seconds,mil)
        timeInDouble = Double(m_s)
        //if mil == 1 {
             fillChart()
      //  }
        print(timeInDouble!)
    }
    
    func fillChart(){
        cList.append(weight_time(weight: Float(.random(in: 1...10)) , time: timeInDouble))
        setupView()
    }

// MARK: test Chart import
    func setupView(){
    
        let controller = UIHostingController(rootView: chartvalues())
        guard let chartView = controller.view else{
            return
        }
            view.addSubview(chartView)
            controller.view.isHidden = false
        
            chartView.snp.makeConstraints{make in
                
            make.centerY.equalToSuperview()
            make.leading.equalToSuperview().offset(15)
            make.trailing.equalToSuperview().inset(15)
            make.height.equalTo(300)
        }
    }
}
import Charts
import Foundation
import AcaiaSDK
import UIKit




struct weight_time:Identifiable {
    let id = UUID()
    let weight: Float
    let time: Double
}

struct chartvalues: View{
    let testList = [
        weight_time( weight: 0.0, time: 0.5),
        weight_time(weight: 0.5, time: 1.0),
        weight_time(weight: 1.2, time: 1.5),
        weight_time(weight: 1.72, time: 2.0),
        weight_time(weight: 2.8, time: 2.5),
        weight_time(weight: 3.0, time: 3.0),
        weight_time(weight: 4.25, time: 3.5),
        weight_time(weight: 4.94, time: 4.0),
        weight_time(weight: 5.62, time: 4.5),
        weight_time(weight: 6.6, time: 5.0)
        
    ]
    
    
    var body: some View{
        if cList != nil {
            Chart(cList){
                weight_time in
                LineMark(
                    x: .value("Time", weight_time.time),
                    y: .value("Weight", weight_time.weight)
                ).foregroundStyle(.red)
                
            }
        }
        
        //Text(cList)
    }
}```